问题描述
所以我在我的 Angular 10 项目中有一个默认的和一个自定义的 spec.ts 文件,并且 Karma 没有检测到它们可以运行。任何线索为什么会发生这种情况?
我的 Karma 配置文件(实际上没有改变):
// 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/korrespo-portal'),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
});
};
我的控制台输出:
Chrome 88.0.4324.104 (Windows 10): Executed 0 of 0 SUCCESS (0.013 secs / 0 secs)
TOTAL: 0 SUCCESS
在 Karma UI 中显示:
Incomplete: No specs found,randomized with seed 27463
我的 ng version
输出:
_ _ ____ _ ___
/ \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|
/ △ \ | '_ \ / _` | | | | |/ _` | '__| | | | | | |
/ ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | |
/_/ \_\_| |_|\__,|\__,_|_|\__,_|_| \____|_____|___|
|___/
Angular CLI: 10.1.7
Node: 12.13.1
OS: win32 x64
Angular: 10.2.0
... animations,common,compiler,compiler-cli,core,forms
... language-service,localize,platform-browser
... platform-browser-dynamic,router
Ivy Workspace: Yes
Package Version
------------------------------------------------------------
@angular-devkit/architect 0.1002.0
@angular-devkit/build-angular 0.1002.0
@angular-devkit/core 10.2.0
@angular-devkit/schematics 10.1.7
@angular/cdk 10.2.5
@angular/cli 10.1.7
@angular/material 10.2.5
@angular/material-moment-adapter 10.2.5
@schematics/angular 10.1.7
@schematics/update 0.1001.7
rxjs 6.6.3
typescript 3.9.7
如上所示,我正在运行 Angular 10 和如上所示的 TypeScript 3.9.7...
解决方法
应该有一个名为 test.ts
的文件,它有这样一行:
// Then we find all the tests.
const context = require.context('./',true,/\.spec\.ts$/);
// And load the modules.
context.keys().map(context);
这些是负责查找测试的行。也许您的测试不在 ./
中。