在角返回模块测试服务是没有定义 [英] Testing service in Angular returns module is not defined
问题描述
我想在我的项目(从GitHub上的角种子项目获得)运行默认服务单元测试,但我不断收到错误模块没有定义。
我已阅读,它可能是与引用的JavaScript文件的的命令,但我似乎无法得到它的工作,所以你希望有可能能够提供帮助。
我对测试配置是这样的:
基本路径='../';
文件= [结果
公共/ JavaScript的/ lib中/ jQuery的-1.8.2.js',结果
公共/ JavaScript的/ lib目录/ angular.js',结果
公共/ JavaScript的/ lib目录/ angular-的 .js文件',结果
公共/ app.js',结果
公共/控制器/ 的.js文件',结果
公共/ directives.js',结果
公共/ filters.js',结果
公共/ services.js',结果
茉莉,结果
JASMINE_ADAPTER,结果
公共/ JavaScript的/ lib目录/角mocks.js',结果
测试/单位/ * JS。'];
autoWatch = TRUE;
浏览器= ['铬'];
junitReporter = {OUTPUTFILE:TEST_OUT / unit.xml',浴室:'单位'
};
块引用>这项服务看起来如下:
angular.module('myApp.services',[])。
值('版本','0.1');测试看起来是这样的:
使用严格的;描述('服务',函数(){
beforeEach(模块('myApp.services'));
描述('版本',函数(){
它('应该返回当前版本,注入(函数(版本){
期待(版本).toEqual('0.1');
}));
});
});和贯穿testacular测试时,错误是这样的:
的ReferenceError:模块没有定义
块引用>解决方案您缺少的角mocks.js 文件。
I am trying to run the default service unit test in my project (Taken from the Angular Seed project on GitHub), but I keep getting the error "module is not defined".
I have read that it could be something to do with the order of the referenced JavaScript files, but I can't seem to get it to work, so hopefully one of you might be able to help.
My configuration for the test looks like this:
basePath = '../';
files = [
'public/javascripts/lib/jquery-1.8.2.js',
'public/javascripts/lib/angular.js',
'public/javascripts/lib/angular-.js',
'public/app.js',
'public/controllers/.js',
'public/directives.js',
'public/filters.js',
'public/services.js',
JASMINE,
JASMINE_ADAPTER,
'public/javascripts/lib/angular-mocks.js',
'test/unit/*.js' ];autoWatch = true;
browsers = ['Chrome'];
junitReporter = { outputFile: 'test_out/unit.xml', suite: 'unit' };
The service looks like the following:
angular.module('myApp.services', []). value('version', '0.1');
The test looks like this:
'use strict'; describe('service', function() { beforeEach(module('myApp.services')); describe('version', function() { it('should return current version', inject(function(version) { expect(version).toEqual('0.1'); })); }); });
And the error when running the test through testacular is this:
ReferenceError: module is not defined
解决方案You are missing the angular-mocks.js file.
这篇关于在角返回模块测试服务是没有定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!