首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >AngularJS中的测试: inject函数的引用错误

AngularJS中的测试: inject函数的引用错误
EN

Stack Overflow用户
提问于 2013-02-08 06:52:24
回答 1查看 15.7K关注 0票数 18

我尝试测试以下代码:

代码语言:javascript
复制
describe('myService test', function () {
    describe('when I call myService.one', function () {
        beforeEach(angular.module('TargetMarketServices'));
        it('returns 1', inject(function (imagesRepository) {
            expect(true).toEqual(true);
        }));

    });

});

当执行这段代码时,我得到这个错误:

代码语言:javascript
复制
TypeError: 'undefined' is not a function (evaluating 'this.func.apply(this.spec)')
    at http://localhost:8080/testacular.js:76
    at http://localhost:8080/context.html:35
ReferenceError: Can't find variable: inject
    at /home/peter/Dropbox/AngularJS/set-component/test/sets/sets-ihm.js:6
    at /home/peter/Dropbox/AngularJS/set-component/test/sets/sets-ihm.js:8
    at /home/peter/Dropbox/AngularJS/set-component/test/sets/sets-ihm.js:10

PhantomJS 1.8:已执行1个(共3个) (1个失败)(跳过2个) (0.072秒/0.01秒)

在我的测试中,我使用了Testacular、Jasmine和PhantomJS。

EN

回答 1

Stack Overflow用户

发布于 2013-02-08 07:45:30

你所在的那行

代码语言:javascript
复制
beforeEach(angular.module('TargetMarketServices'));

应该是

代码语言:javascript
复制
beforeEach(module('TargetMarketServices'));

如果查看测试/单元/directivesSpec.js中的angular-phonecat项目,就会发现它使用

代码语言:javascript
复制
beforeEach(module('myApp.directives'));

如果我将其修改为使用angular.module:

代码语言:javascript
复制
beforeEach(angular.module('myApp.directives'));

然后我在运行testacular时也得到了这个错误:

代码语言:javascript
复制
TypeError: 'undefined' is not a function (evaluating 'this.func.apply(this.spec)')
票数 13
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14762605

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档