[英]Property 'Ajax' does not exist on type 'typeof jasmine'
I'm trying to install the jasmine plugin "jasmine-ajax" in an angular-cli project. 我正在尝试在angular-cli项目中安装jasmine插件“jasmine-ajax”。 The instructions seem pretty standard, but I keeping getting this error:
说明似乎很标准,但我一直收到这个错误:
"ERROR in src/app/app.component.spec.ts(8,13): error TS2339: Property 'Ajax' does not exist on type 'typeof jasmine'." “src / app / app.component.spec.ts(8,13)中的错误:错误TS2339:'typeof jasmine'类型中不存在属性'Ajax'。”
I keep seeing an error on jasmine.Ajax.install() 我一直看到jasmine.Ajax.install()上的错误
In my karma.conf.js file, I have this: 在我的karma.conf.js文件中,我有这个:
module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine-ajax', 'jasmine', '@angular/cli'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'),
require('@angular/cli/plugins/karma'),
require('karma-jasmine-ajax')
],
client:{
clearContext: false // leave Jasmine Spec Runner output visible in browser
},
coverageIstanbulReporter: {
reports: [ 'html', 'lcovonly' ],
fixWebpackSourcePaths: true
},
angularCli: {
environment: 'dev'
},
reporters: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false
});
};
I also tried to add the plugin using the helpers section in the jasmine.json. 我还尝试使用jasmine.json中的helpers部分添加插件。 This is what my jasmine.json file looks like:
这是我的jasmine.json文件的样子:
{
"spec_dir": "spec",
"spec_files": [
"**/*[sS]pec.js"
],
"helpers": [
"helpers/**/*.js",
"../../../node_modules/jasmine-ajax/lib/mock-ajax.js"
],
"stopSpecOnExpectationFailure": false,
"random": true
}
Has anyone installed the jasmine-ajax plugin successfully lately? 有没有人最近成功安装了jasmine-ajax插件?
Could it be the version of jasmine-ajax? 它可能是jasmine-ajax的版本吗?
You are on the rigth path. 你正处于艰难的道路上。 You need to install the type definitions for TypeScript:
您需要安装TypeScript的类型定义:
npm i @types/jasmine-ajax
and include them in your e2e/tsconfig.e2e.json : 并将它们包含在您的e2e / tsconfig.e2e.json中 :
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../out-tsc/e2e",
"baseUrl": "./",
"module": "commonjs",
"target": "es5",
"types": [
"jasmine",
"jasminewd2",
"node",
"jasmine-ajax"
]
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.