【发布时间】:2020-03-31 11:02:49
【问题描述】:
出于某种我无法理解的原因,Karma 说 Jasmine 找不到我的任何测试规范。我正在使用 Angular 9、Typescript 和 ng test 来运行测试。我还运行 jasmine init 来创建 jasmine.json 配置文件。我已经尝试了几次配置更改,创建了一个虚拟测试 javascript 文件等等,但我仍然收到相同的“未找到规范”消息。这真的令人沮丧,我敢肯定我只是在这里忽略了一些明显的东西。
测试文件夹结构:
spec
services
address.service.spec.ts
login.service.spec.ts
...
support
jasmine.json
jasmine.json:
{
"spec_dir": "spec",
"spec_files": [
"**/*[sS]pec.js", // tried with "**/*[sS]pec.ts"
"services/*[sS]pec.js" // tried with "services/*[sS]pec.ts"
],
"helpers": [
"helpers/**/*.js" // tried with "helpers/**/*.ts"
],
"stopSpecOnExpectationFailure": false,
"random": false
}
karma.conf.js:
// Karma configuration file, see link for more information
// https://karma-runner.github.io/1.0/config/configuration-file.html
module.exports = function(config) {
config.set({
basePath: '',
frameworks: ['jasmine', '@angular-devkit/build-angular'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'),
require('@angular-devkit/build-angular/plugins/karma'),
],
client: {
clearContext: false, // leave Jasmine Spec Runner output visible in browser
},
coverageIstanbulReporter: {
dir: require('path').join(
__dirname,
'./coverage/censored',
),
reports: ['html', 'lcovonly', 'text-summary'],
fixWebpackSourcePaths: true,
},
reporters: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false,
restartOnFileChange: true,
});
};
【问题讨论】:
-
由于Angular 9还没有发布,我建议你在github上提出一个问题,因为更多的人可能会遇到这种情况,需要核心团队来解决。
-
我可能应该验证它是否可以预先与 Angular 8 一起使用。
标签: angular typescript testing jasmine karma-runner