[英]ReferenceError : AngularJS is not defined on Karma with Jasmine unit testing
I'm actually stuck since few hours, my boss wants me to proceed to unit testing on the functionalities i coded last week, when I do my karma start karma.conf.js
it gives me the following issue : 几个小时以来,我实际上一直处于停滞状态,我的老板希望我对上周编写的功能进行单元测试,当我执行karma启动karma.conf.js
它出现了以下问题:
"message": "An error was thrown in afterAll\\nUncaught ReferenceError: angular is not defined",
my files structure : 我的文件结构:
webapp
-www
-services
api.service.js
-test
test.test.js
karma.conf.js
essential of karma.conf.js : karma.conf.js的基本要素:
module.exports = function(config) {
config.set({
files: [
'www/js/services/api.service.js',
'test/**/*.test.js'
],
})
}
I think Karma doesn't find my api.service.js but i don't know why, the angularjs code actually work in the webapp. 我认为Karma找不到我的api.service.js,但我不知道为什么,angularjs代码实际上可在webapp中工作。
content of my test.test.js : 我的test.test.js的内容:
(function() {
'use strict';
describe('apiService', function() {
it('should return an array of object', function() {
var artist = typeof getArtist(118680); // MGMT Artist
console.log(artist);
expect(artist).toEqual('array');
});
});
})();
getArtist is the function I need to test situated in api.service.js. getArtist是我需要测试的函数,位于api.service.js中。
Thank you, 谢谢,
Paul. 保罗。
Karma needs the angular file to test angularJS code. 业力需要角度文件来测试angularJS代码。 You need to include it in the files array in the karma configuration. 您需要将其包含在业力配置的文件数组中。
module.exports = function(config) {
config.set({
files: [
'path-to-angular.js',
'www/js/services/api.service.js',
'test/**/*.test.js'
],
})
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.