出于某种我无法理解的原因,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,
});
};
最佳答案
我今天有这个错误,对我来说是我的 .ts
文件中有语法级错误,所以它们无法真正编译。
在上述情况下,我认为,测试不应该开始(而是显示编译错误)。
但无论出于何种原因,测试以某种方式开始,Jasmine
失败并显示“No specs found
”日志。
关于angular - Jasmine:Angular Typescript 项目中的 "Incomplete: No specs found",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59213365/