【问题标题】:module not found when setting angular controller test设置角度控制器测试时找不到模块
【发布时间】:2014-04-22 15:22:15
【问题描述】:

我尝试在guide之后设置角度控制器单元测试,代码如下:

describe('ProfileController', function() {
// load haloApp module
beforeEach(module('haloApp'));

it("should have notify_changed in scope", inject(function($controller) {
    var scope= {},
    ctrl = $controller('ProfileController', {$scope:scope});// inject controller
    // expect(ProfileController).not.toBeDefined();
    expect(scope.notify_changed).toBe(false);
}));

});

当我用 jasmine 运行这个测试用例时,它报告了以下错误:

ReferenceError: module is not defined

我在此代码 sn-p 之前需要 angular 文件。我有什么遗漏吗?

【问题讨论】:

  • 你是否包含了 angular-mocks.js?
  • 你能包括你的控制器的代码,至少是声明,而不是实现吗?

标签: angularjs unit-testing jasmine angularjs-scope jasmine-headless-webkit


【解决方案1】:

module 函数是 angular-mocks.js 中定义的ngMock 模块的一部分。确保在运行测试时包含该文件。见https://docs.angularjs.org/api/ngMockhttps://docs.angularjs.org/api/ngMock/function/angular.mock.module

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-02-15
    • 2017-05-13
    • 1970-01-01
    • 2015-10-27
    • 2014-09-17
    • 2022-01-07
    • 2022-01-21
    • 1970-01-01
    相关资源
    最近更新 更多