2016-12-05 104 views
0

单元测试我的angular2/ionic2应用程序时遇到了有线问题。 我为应用程序编写了一些单元测试,当我点击npm test时,它们正常测试。但是今天当我点击npm test时,它没有检测到我的项目的任何单元测试。它在终端中提供以下输出。Jasmine Karma单元测试在Angular2中未检测到我的测试用例单元测试

[email protected]:/media/dilanka/Stuff/CODE BASE/Inspection/UnitTesting/Inspection-Rewrite$ npm test 

> [email protected] test /media/dilanka/Stuff/CODE BASE/Inspection/UnitTesting/Inspection-Rewrite 
> ng test --code-coverage 

05 12 2016 13:10:45.485:WARN [karma]: No captured browser, open http://localhost:9876/ 
05 12 2016 13:10:45.492:WARN [karma]: Port 9876 in use 
05 12 2016 13:10:45.493:INFO [karma]: Karma v1.3.0 server started at http://localhost:9877/ 
05 12 2016 13:10:45.493:INFO [launcher]: Launching browser Chrome with unlimited concurrency 
05 12 2016 13:10:45.497:INFO [launcher]: Starting browser Chrome 
05 12 2016 13:10:47.739:INFO [Chrome 55.0.2883 (Linux 0.0.0)]: Connected on socket /#9FP78x92YrV-nPNoAAAA with id 77141340 

START: 

Finished in 0.003 secs/0 secs 

SUMMARY: 
✔ 0 tests completed 

但在其他计算机,同一分支运行npm install没有任何疑虑。它可以检测所有的测试用例。 然后我在我的电脑上重新安装了节点和npm。但是,我仍然遇到同样的情况。 然后我在这个项目上运行npm test进行检查(https://github.com/lathonez/clicker),它也给出了相同的结果,并且没有检测到任何测试用例。以前这个项目也可以在我的电脑上完美运行。

我不明白发生了什么问题。问题是我的nodenpmkarma configurations

请帮帮我。谢谢...

回答

3

它看起来像一个铬版本55的问题。今天早上我们有同样的问题,我们更新了karma配置文件使用firefox而不是chrome。

对于在Firefox中运行测试,您需要添加karma-firefox-launcher插件并将浏览器更改为Firefox。

plugins: [ 
    require('karma-jasmine'), 
    require('karma-firefox-launcher'), 
    require('karma-remap-istanbul'), 
    require('angular-cli/plugins/karma') 
], 


browsers: ['Firefox'], 

编辑

之所以能够通过添加以下行来得到这个工作铬karma.conf.js文件。

mime: { 'text/x-typescript': ['ts','tsx'] } 

来源:https://github.com/angular/angular-cli/issues/2125

+0

非常感谢您的回答。现在它工作完美。我花了整整一天的时间来找出错误。但是我没有注意到这个问题。浪费了我整整一天的时间。不管怎么说,还是要谢谢你。 :) –