我已经设置了一个使用Karma和Jasmine运行测试的grunt任务来测试AngularJS框架!
由于某些原因,我用于其他项目的相同配置因此而失败。这是我收到的错误消息:
forEach@/home/username/sw-projects/project/bower_components/angular/angular.js:340:24
loadModules@/home/username/sw-projects/project/van/bower_components/angular/angular.js:4419:12
createInjector@/home/username/sw-projects/project//bower_components/angular/angular.js:4344:22
workFn@/home/jofomah/sw-projects/van/bower_components/angular-mocks/angular-mocks.js:2409:60
/home/username/sw-projects/project/bower_components/angular/angular.js:4459:53
Expected undefined to be defined.
/home/username/sw-projects/project/app/common/utility/utility.service.spec.js:16:34
我的Karma配置:
// Karma配置 //生成于2016年3月18日星期五14:24:49 GMT + 0100(WAT)
var bowerJS = require('wiredep')({
dependencies: true,
exclude: [/jasmine$/],
devDependencies: true
}).js;
module.exports = function(config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['jasmine'],
// list of files / patterns to load in the browser
files: bowerJS.concat([
'.tmp/*.js',
// 'config.js',
// 'country-config.js',
'app/routes.js',
'app/app.js',
'app/common/rest/rest-client.js',
'app/common/utility/utility.service.js',
'app/common/settings/settings.js',
'app/common/brand/brand.directive.js',
'app/common/footer/footer.directive.js',
'app/common/week-picker/week-picker.directive.js',
'app/common/state-selector/state-selector.directive.js',
'app/common/loading-blanket/loading-blanket.directive.js',
'app/common/transform-listener/transform-listener.module.js',
'app/common/transform-listener/transform-listener.service.js',
'app/common/transform-listener/transform-listener-client.factory.js',
'app/common/http-error-modal/http-error-modal.js',
'app/modules/dashboards/index.js',
'app/modules/dashboards/state-dashboards.service.js',
'app/modules/dashboards/zone-dashboards.service.js',
'app/modules/data/dashboard/dashboard.controller.js',
'app/modules/data/upload/upload-form.directive.js',
'app/modules/data/inbox/inbox.controller.js',
'app/modules/data/inbox/inbox.service.js',
'app/modules/data/index.js',
'app/modules/users/users.service.js',
'app/modules/users/login-form/login-form.directive.js',
'app/modules/users/user-management-navbar-el/user-management-navbar-el.directive.js',
'app/modules/users/password-reset/password-reset.directive.js',
'app/modules/users/index.js',
'app/modules/settings/indices/index.directive.js',
'app/modules/settings/indices/indicator.directive.js',
'app/modules/settings/indices/indices.directive.js',
'app/modules/settings/indices/index.js',
'app/modules/settings/entities/entities.directive.js',
'app/modules/settings/entities/index.js',
'app/modules/settings/index.js',
'app/modules/analysis/chart.directive.js',
'app/modules/analysis/bar/bar.controller.js',
'app/modules/analysis/matrix/matrix.controller.js',
'app/modules/analysis/stock/stock.controller.js',
'app/modules/analysis/products.constant.js',
'app/modules/analysis/index.js',
'app/modules/entities/typeahead/agencies/agencies.directive.js',
'app/modules/entities/typeahead/districts/districts.directive.js',
'app/modules/entities/typeahead/regions/regions.directive.js',
'app/modules/entities/typeahead/sites/sites.directive.js',
'app/modules/entities/typeahead/zones/zones.directive.js',
'app/modules/entities/typeahead/index.js',
'app/modules/entities/admin/sites.directive.js',
'app/modules/entities/admin/site.directive.js',
'app/modules/entities/admin/zones.directive.js',
'app/modules/entities/admin/zone.directive.js',
'app/modules/entities/admin/regions.directive.js',
'app/modules/entities/admin/region.directive.js',
'app/modules/entities/admin/districts.directive.js',
'app/modules/entities/admin/district.directive.js',
'app/modules/entities/admin/index.js',
'app/modules/entities/entities.service.js',
'app/modules/entities/index.js',
//
//'app/**/*.module.js',
//'app/**/*.js',
//'app/**/*.service.js',
'app/**/*.spec.js',
//'app/**/*.html'
]),
// list of files to exclude
exclude: [
],
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
},
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress'],
// web server port
port: 9876,
// enable / disable colors in the output (reporters and logs)
colors: true,
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_DEBUG,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: false,
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['PhantomJS'],
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: true,
plugins: [
'karma-*'
]
}) }
我的测试是:
'use strict';
/*global module: false, inject: false */
describe('utility', function(){
var utility;
beforeEach(module('eha.van.utility'));
beforeEach(inject(function(_utility_){
utility = _utility_
}));
it('should be defined', function(){
expect(utility).toBeDefined();
});
});