未定义 Angular 返回模块中的测试服务 [英] Testing service in Angular returns module is not defined

查看:30
本文介绍了未定义 Angular 返回模块中的测试服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的项目中运行默认服务单元测试(取自 GitHub 上的 Angular Seed 项目),但我不断收到错误模块未定义".

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".

我读到这可能与 引用的 JavaScript 文件的顺序有关,但我似乎无法让它工作,所以希望你们中的一个人可以提供帮助.

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.

我的测试配置如下:

basePath = '../';

basePath = '../';

文件 = [
'public/javascripts/lib/jquery-1.8.2.js',
'public/javascripts/lib/angular.js',
'public/javascripts/lib/angular-.js',
'公共/app.js',
'公共/控制器/
.js',
'public/directives.js',
'公共/过滤器.js',
'公共/services.js',
茉莉花,
茉莉花适配器,
'public/javascripts/lib/angular-mocks.js',
'测试/单元/*.js'];

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;

autoWatch = true;

浏览器 = ['Chrome'];

browsers = ['Chrome'];

junitReporter = { outputFile: 'test_out/unit.xml', 套件: 'unit'};

junitReporter = { outputFile: 'test_out/unit.xml', suite: 'unit' };

服务如下所示:

angular.module('myApp.services', []).
  value('version', '0.1');

测试如下:

'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');
    }));
  });
});

而通过 testacular 运行测试时的错误是这样的:

And the error when running the test through testacular is this:

ReferenceError: 模块未定义

ReferenceError: module is not defined

推荐答案

您缺少 angular-mocks.js 文件.

这篇关于未定义 Angular 返回模块中的测试服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆