我想在名为Clip-two的模板中运行业力测试。
当我开始karma conf
karma start my.conf.js
这是我的错误:
25 05 2017 11:36:10.911:WARN [业力]:没有捕获的浏览器,打开http://localhost:9876/ Chrome 49.0.2623(Mac OS X 10.7.5)用户工厂应该存在FAILED 错误:[$ injector:modulerr] http://errors.angularjs.org/1.4.7/ $ injector / modulerr?p0 = clip-two& p1 = Error%3A%20%5B%24injector%3Amodulerr%5D%20http%3A%2F%2Ferrors.angularjs。有机%2F1.4.7%2F%24injector%2Fmodulerr%3Fp0%3DngCookies%26P1%3DError%253A%2520%255B%2524injector%253Anomod%255D%2520http%253A%252F%252Ferrors.angularjs.org%252F1.4.7%252F% 2524injector%252Fnomod%253Fp0%253DngCookies%250A%2520%2520%2520%2520at%2520Error%2520(天然)%250A%2520%2520%2520%2520at%2520http%253A%252F%252Flocalhost%253A9876%252Fbase%252Fbower_components%252Fangular %252Fangular.min.js%253Fb6b56d0e096efc26e09d6 ... cc346%3A41 3A35%)%0A%20%20%20%20原子%20Object.workFn%20(HTTP%3A%2F%2Flocalhost%3A9876%2Fbase%2Fbower_components%2Fangular-嘲笑%2Fangular-mocks.js%3Fe9f36bdb59779aa33da5eab3dfd5ffda120d58aa%3A2427%3A52)
我的业力骗局是由karma init命令完成的。我只添加了所有文件
module.exports = function(config) {
config.set({
basePath: '',
frameworks: ['jasmine'],
angular: ['mocks'],
// list of files / patterns to load in the browser
files: [
'bower_components/angular/angular.min.js',
'bower_components/angular-animate/angular-animate.min.js',
'bower_components/angular-touch/angular-touch.min.js',
'bower_components/angular-sanitize/angular-sanitize.min.js',
'bower_components/angular-ui-router/release/angular-ui-router.min.js',
'bower_components/angular-mocks/angular-mocks.js',
'bower_components/ngstorage/ngStorage.min.js',
'bower_components/angular-translate/angular-translate.min.js',
'bower_components/angular-translate-loader-url/angular-translate-loader-url.min.js',
'bower_components/angular-translate-loader-static-files/angular-translate-loader-static-files.min.js',
'bower_components/angular-translate-storage-local/angular-translate-storage-local.min.js',
'bower_components/angular-translate-storage-cookie/angular-translate-storage-cookie.min.js',
'bower_components/oclazyload/dist/ocLazyLoad.min.js',
'bower_components/angular-breadcrumb/dist/angular-breadcrumb.min.js',
'bower_components/angular-bootstrap/ui-bootstrap-tpls.min.js',
'bower_components/angular-loading-bar/build/loading-bar.min.js',
'bower_components/angular-scroll/angular-scroll.min.js',
'STANDARD/assets/js/app.js',
'STANDARD/assets/js/main.js',
'STANDARD/assets/js/config.constant.js',
'STANDARD/assets/js/config.router.js',
'STANDARD/assets/js/services/agente.js',
'STANDARD/assets/js/controllers/inboxCtrl.js',
'STANDARD/assets/test/*.js'
],
exclude: [
],
preprocessors: {
},
reporters: ['progress'],
port: 9876,
colors: true,
logLevel: config.LOG_WARN,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false,
concurrency: Infinity
})
}
这是我的单元测试
describe('Users factory', function() {
// Before each test load our api.users module
beforeEach(module('clip-two'));
// Before each test set our injected Users factory (_Users_) to our local Users variable
var $controller;
beforeEach(angular.mock.inject(function(_$controller_){
$controller = _$controller_;
}));
// A simple test to verify the Users factory exists
it('should exist', function() {
expect($controller).toBeDefined();
});
});
那是我的app.js
'use strict';
angular.module("clip-two", [
'ngAnimate',
'ngCookies',
'ngStorage',
'ngSanitize',
'ngTouch',
'ui.router',
'ui.bootstrap',
'oc.lazyLoad',
'cfp.loadingBar',
'ncy-angular-breadcrumb',
'duScroll',
'pascalprecht.translate',
]);
一些建议?
答案 0 :(得分:1)
错误表明测试中的ngCookies存在问题。
当我查看你的业力配置文件时,我看不到包含ngcookies的文件。
您可能只需要在karma.conf中添加它以使其正常工作。
答案 1 :(得分:1)
考虑到错误,似乎在运行业力时,无法联系到主机。 您可以通过http://localhost:9876/访问您的申请吗?
您可以尝试再次运行它们,同时保持浏览器在上述地址上打开,我知道它似乎没有意义,但在某些系统上,这可以解决问题。
然后看看你的业力文件,也许有一些依赖项缺失。确保包含所需的所有文件,否则当测试运行时,您可能会遇到很少的故障。
但我可以理解,现在重要的是测试运行:D