【发布时间】:2017-04-06 04:23:47
【问题描述】:
我正在使用 karma 和 jasmine 对 angular js 进行单元测试,但它会产生以下错误。
Chrome 54.0.2840 (Mac OS X 10.11.6) LOG: 'WARNING: Tried to load angular more than once.'
Chrome 54.0.2840 (Mac OS X 10.11.6) ERROR
Uncaught TypeError: window.angular.$$csp is not a function
at node_modules/angular/angular.js:31768
我已经附上了我的 karma.conf.js 文件和下面的 angular 模块。
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', 'ng-scenario'],
// list of files / patterns to load in the browser
files: [
'./node_modules/angular/angular.js',
'./node_modules/angular-ui-router/release/angular-ui-router.js',
'./node_modules/angular-mocks/angular-mocks.js',
'./app/**/*.js',
'./test/logger/loggerControllerTest.js'
],
// 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_INFO,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['Chrome'],
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: false,
// Concurrency level
// how many browser should be started simultaneous
concurrency: Infinity
})
}
以下是角度模块创建sn-p。
var app = angular.module("gradchatApp", [
ngRoute,
ngAnimate,
ngAria,
ngMessages,
ngResource,
ngSanitize,
ngTouch,
ngCookies,
angularMoment,
angularMaterial,
'ngDialog',
'infinite-scroll',
require( 'angular-bootstrap-npm' )
]);
请帮我解决上述错误。
【问题讨论】:
标签: javascript angularjs node.js karma-jasmine