![](/img/trans.png)
[英]Angular using Jasmine and Karma getting - Incomplete: No specs found
[英]Jasmine: "Incomplete: No specs found" in Angular Typescript project
出於某種我無法理解的原因,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
}
業力.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,
});
};
解決了。 一旦我將 .spec 文件移動到 /src 文件夾中,Jasmine 就可以毫無問題地檢測到它們。
我遇到了同樣的問題,但在我的情況下,我從 angular 9 升級到 angular 10 並且測試停止運行,我得到了很多:
src/app/xxxxx/basic-info/basic-info.component.spec.ts:391:9 - error TS2532: Object is possibly 'undefined'.
391 this.whatToDelete = ["mumbo", "jumbo"];
因此,在“描述”中,我將箭頭函數更改為常規函數,因為箭頭函數沒有自己的“this”
*
與常規函數不同,箭頭函數沒有自己的 this 。 箭頭函數中 this 的值在函數的整個生命周期中保持不變,並且始終綁定到最近的非箭頭父函數中的 this 值。
希望這可以幫助你們中的一個並為您節省一些時間
我今天遇到了錯誤,對我來說是我的 .ts 文件中有錯誤,所以它無法真正編譯。 通常我認為它也不會開始測試。 但在這種情況下,測試開始了,但出現了這個錯誤。
一旦我將 .spec 文件移動到 /spec 目錄中,它就會找到測試。
我有一個類似的問題,顯然是由於導入無效。
這是特定的導入: import 'rxjs/add/observable/throw'
我剛剛刪除了導入,一切正常。
ng test 似乎執行得很好,所以有點混亂。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.