Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular Karma测试运行两次_Angular_Typescript_Unit Testing_Jasmine_Karma Jasmine - Fatal编程技术网

Angular Karma测试运行两次

Angular Karma测试运行两次,angular,typescript,unit-testing,jasmine,karma-jasmine,Angular,Typescript,Unit Testing,Jasmine,Karma Jasmine,我们有一个在jasmine中进行单元测试的Angular项目。我有一个问题,每次我保存一个文件时,我所有的单元测试都会运行两次(使用autowatch) 我发现这篇文章显示了一个类似的问题:。由于我们的文件是Typescript,我尝试了以下方法: { pattern: "**/*.ts", watched: false, served: true, included: true } ,但如果我将文件模式设置为Typescript,则这不起作用。它给出了以下错误: 警告[中间件:karma]:

我们有一个在jasmine中进行单元测试的Angular项目。我有一个问题,每次我保存一个文件时,我所有的单元测试都会运行两次(使用autowatch)

我发现这篇文章显示了一个类似的问题:。由于我们的文件是Typescript,我尝试了以下方法:

{ pattern: "**/*.ts", watched: false, served: true, included: true }
,但如果我将文件模式设置为Typescript,则这不起作用。它给出了以下错误: 警告[中间件:karma]:无效文件类型(ts),默认为js

这是我的karma.conf.js文件:

//Karma配置文件,有关详细信息,请参阅链接
// https://karma-runner.github.io/1.0/config/configuration-file.html
module.exports=函数(配置)
{
config.set({
基本路径:“”,
框架:['jasmine','angular devkit/build angular'],
插件:[
需要(“噶玛茉莉花”),
需要('karma-chrome-launcher'),
要求('karma-jasmine-html-reporter'),
要求(“karma-coverage-istanbul-reporter”),
需要(“@angular devkit/build angular/plugins/karma”),
要求('karma-junit-reporter')
],
客户:{
clearContext:false//使Jasmine Spec Runner输出在浏览器中可见
},
报道者:{
dir:require('path').join('uuu dirname,../coverage'),
报告:['html'、'cobertura'、'lcovonly'],
FixWebPackageSourcePath:true
},
茉莉花:{
随机:假
},
junitReporter:{
outputdir:“”,
outputFile:“test angular.xml”
},
记者:['progress','kjhtml','junit'],
港口:9876,
颜色:对,
日志级别:config.LOG\u INFO,
自动观察:没错,
autoWatchBatchDelay:10000,
浏览器:['Chrome'],
单程:错,
档案:[
{pattern:'../node_modules/@angular/material/prebuilded themes/indigo pink.css',include:true,waved:true}
]
});

};更新到Angular fixed it的最新版本

为什么karma.conf中包含靛蓝粉.css
?如果删除
文件
,并将其包括到
节点_模块
,会发生什么情况?我不确定这是否有帮助,但奇怪的是,我们在这里包含了这个文件?具体来说,应该有一个名为test的部分链接到您的karma.conf.js以及test.ts文件。还有,你的测试中是什么?在angular的较新版本中,这是指向要运行的文件的内容,它应该看起来像“const context=require.context('./',true,/\.spec\.ts$/);”这表示加载以“.spec.ts”结尾的任何文件。另外,如果您在chrome运行测试时在chrome中打开dev tools,您会在console中看到任何错误吗?@tenkmilan I按照您的建议删除了文件部分,但没有任何更改。一切都还在运转twice@WesleyTrantham我添加了你在原始问题中建议的2个文件。他们似乎很有条理。你看到任何可能导致这种情况的东西了吗?我们通过升级到Karma的最新版本来解决这个问题