我尝试测试以下代码:
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);
}));
});
});
当执行这段代码时,我得到这个错误:
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。
发布于 2013-02-08 07:45:30
你所在的那行
beforeEach(angular.module('TargetMarketServices'));
应该是
beforeEach(module('TargetMarketServices'));
如果查看测试/单元/directivesSpec.js中的angular-phonecat项目,就会发现它使用
beforeEach(module('myApp.directives'));
如果我将其修改为使用angular.module:
beforeEach(angular.module('myApp.directives'));
然后我在运行testacular时也得到了这个错误:
TypeError: 'undefined' is not a function (evaluating 'this.func.apply(this.spec)')
https://stackoverflow.com/questions/14762605
复制相似问题