测试在AngularJS:进样功能的引用错误 [英] Tests in AngularJS: Reference error of the inject function
问题描述
我尝试测试下面的code:
I try to test the code below:
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);
}));
});
});
在执行此code我得到这个错误:
When this code is executed I get this error:
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秒)
PhantomJS 1.8: Executed 1 of 3 (1 FAILED) (skipped 2) (0.072 secs / 0.01 secs)
有关我的测试中,我使用Testacular茉莉和PhantomJS。
For my test, I use Testacular with Jasmine and PhantomJS.
推荐答案
AngularJS提供了两个测试库:
AngularJS provides two testing libraries:
- 角mocks.js
- 角scenario.js
角嘲笑用于茉莉花和噶测试。它出版的全球方法模块()和注入()在你的茉莉花规格的测试中使用。这意味着你必须加载角mocks.js脚本(您加载angular.js库/脚本之后)
angular-mocks is used for Jasmine and Karma testing. It publishes global methods module() and inject() to be used in your Jasmine spec tests. This means you must load the angular-mocks.js script (after you load the angular.js library/script)
角方案仅用于端到端测试
angular-scenario is only used for e2e testing.
这篇关于测试在AngularJS:进样功能的引用错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!