简体   繁体   English

ReferenceError:在Jasmine单元测试的Karma上未定义AngularJS

[英]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.

相关问题 AngularJS:未定义$ location路径:单元测试。 卡玛 - 茉莉花 - AngularJS: $location path not defined: Unit Testing. Karma-Jasmine AngularJS&Jasmine / Karma - 未捕获的ReferenceError:未定义require - AngularJS & Jasmine/Karma - Uncaught ReferenceError: require is not defined ReferenceError:spyOn未定义Angularjs / Karma / Jasmine - ReferenceError: spyOn is not defined Angularjs/Karma/Jasmine 使用Jasmine和Karma / AngularJS项目进行单元测试 - Unit testing using Jasmine and Karma / AngularJS project AngularJS + Karma + Jasmine 控制器单元测试: - AngularJS + Karma + Jasmine Controller Unit testing : Karma / Jasmine单元测试具有依赖关系的AngularJS服务 - Karma/Jasmine Unit Testing an AngularJS Service with Dependencies 使用Karma和Jasmine测试angularjs指令-模块未定义 - Testing angularjs directive with Karma and Jasmine - module is not defined AngularJS-业力测试茉莉花-描述未定义 - AngularJS -Karma testing Jasmine- describe is not defined 单元测试AngularJS:未捕获错误:[$ injector:nomod]模块不可用! 和ReferenceError:运行Karma时未定义模块 - Unit-Testing AngularJS: Uncaught Error: [$injector:nomod] Module is not available! and ReferenceError: module is not defined when run Karma 使用Jasmine和Karma测试离子-未捕获的ReferenceError:角度未定义 - Testing Ionic with Jasmine and Karma - Uncaught ReferenceError: angular is not defined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM