2017-08-27 56 views
0

我有一个AngularJS 1.5.11应用程序,其中RequireJS 2.2.0在任何地方都被使用。单元测试是必需的。我甚至无法执行虚拟测试。请指教。Karma执行的零测试(AngularJS,RequireJS)

错误:

PhantomJS 2.1.1 (Linux 0.0.0): Executed 0 of 0 ERROR (0.044 secs/0 secs)

详细的调试水平输出从karma start --browsers PhantomJS_custom --log-level debug命令:https://gist.github.com/sergibondarenko/1120d211aa2265b76669cd831495a6c1

测试: 应用程序/控制器/ __测试__/loginController.spec.js

define('loginController', [], function() { 
    describe('loginController', function() { 
    it('dymmy test', function() { 
     expect(true).toBe(false); 
    }); 
    }); 
}); 

Karma配置:https://gist.github.com/sergibondarenko/4b305341faa24883cb90e6f8f7490d74

试验主要:https://gist.github.com/sergibondarenko/6aa25bf71bfadf39883a59d7cda57a65

开发的依赖关系:

:~/dev/qxip/hepic$ grep -rn devD package.json -A 9 
20: "devDependencies": { 
21- "jasmine": "^2.8.0", 
22- "jasmine-core": "^2.4.1", 
23- "karma": "^0.13.22", 
24- "karma-browserify": "^5.1.1", 
25- "karma-jasmine": "^0.3.8", 
26- "karma-phantomjs-launcher": "^1.0.4", 
27- "protractor": "^4.0.9", 
28- "watchify": "^3.9.0" 
29- }, 

该应用程序结构如下。一些库位于node_modules,其他库位于lib文件夹中。

u[email protected]:~/dev$ tree -L 1 theapp 
theapp 
├── app 
├── css 
├── font-awesome 
├── fonts 
├── img 
├── index.html 
├── karma.conf.js 
├── lang 
├── lib 
├── node_modules 
├── package.json 
├── README.md 
├── resources 
├── scripts 
├── share 
├── templates 
├── test-main.js 
├── tests 
└── widgets 

如果您需要更多信息,请告诉我。

+0

你在哪里运行你的测试?另外,你能列出test-main.js的完整路径,而不仅仅是karma.conf.js中的文件名吗? – 82Tuskers

+0

@ 82Tuskers我运行命令'karma start --browsers PhantomJS_custom --log-level debug'从我的app根文件夹 - “〜/ dev/theapp'。 test-main.js的完整路径是'〜/ dev/theapp/test-main.js',请看上面的应用程序结构。 – trex

+0

你可以在名为test的app下添加一个文件夹吗?即'/ app/test /',然后将你的测试文件添加为'test-file.spec.js'。让我知道这是否有效。 – 82Tuskers

回答

0

在你karma.conf.js一套这样的:

browsers: ['PhantomJS', 'PhantomJS_custom'], 

    // you can define custom flags 
    customLaunchers: { 
     'PhantomJS_custom': { 
     base: 'PhantomJS', 
     options: { 
      windowName: 'my-window', 
      settings: { 
      webSecurityEnabled: false 
      }, 
     }, 
     flags: ['--load-images=true'], 
     debug: true 
     } 
    }, 

    phantomjsLauncher: { 
     // Have phantomjs exit if a ResourceError is encountered (useful if karma exits without killing phantom) 
     exitOnResourceError: true 
    } 

然后假设你有你的karma.conf.js文件中的根,同样的水平,你的app子文件夹,你的test-main.js是,通过执行你的测试:

karma start karma.conf.js 
+0

但我已经有这部分,看看上面的第二个要点https://gist.github.com/sergibondarenko/4b305341faa24883cb90e6f8f7490d74#file-karma-conf-js-L60 – trex

+0

那么你的文件结构呢?是否如解释的那样? – quirimmo

+0

是的,正确的,正如解释 – trex

相关问题