gpt4 book ai didi

javascript - AngularJS 的 Karma 不起作用

转载 作者:行者123 更新时间:2023-11-28 05:18:49 25 4
gpt4 key购买 nike

我使用 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
})
}

以下是 Angular 模块创建片段。

var app = angular.module("gradchatApp", [
ngRoute,
ngAnimate,
ngAria,
ngMessages,
ngResource,
ngSanitize,
ngTouch,
ngCookies,
angularMoment,
angularMaterial,
'ngDialog',
'infinite-scroll',
require( 'angular-bootstrap-npm' )
]);

请帮我解决上述错误。

最佳答案

您是否尝试使用单独的模板(使用 templateUrl)对指令进行单元测试?

这种情况以前发生在我身上,当时我在 templateUrl 中犯了一个错误,找不到模板,默认情况下,每个未找到的查询都被重定向到 index.html,而后者又包含 angular.js。

也许你也有同样的问题?

关于javascript - AngularJS 的 Karma 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40742788/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com