我正在使用带有 Jasmine 的 Testem 来设置一个环境,以便在我的 AngularJS 应用程序中开始单元测试。在我第一次尝试使用注射器之前,一切都很好。这是我回来的:
测试.js
describe('Custom events', function(){
beforeEach(module('AlchemyAdmin'));
beforeEach(inject());
it('should work', function() {
});
});
错误控制台输出:
Custom events should work.
✘ Error: [$injector:modulerr] http://errors.angularjs.org/1.2.25/$in
jector/modulerr?p0=AlchemyAdmin&p1=Error%3A%20%5B%24injector%3Amodulerr%
5D%20http%3A%2F%2Ferrors.angularjs.org%2F1.2.25%2F%24injector%2Fmodulerr
%3Fp0%3DdateRangePicker%26p1%3DError%253A%2520%255B%2524injector%253Amod
ulerr%255D%2520http%253A%252F%252Ferrors.angularjs.org%252F1.2.25%252F%2
524injector%252Fmodulerr%253Fp0%253Dpasvaz.bindonce%2526p1%253DError%252
53A%252520%25255B%252524injector%25253Anomod%25255D%252520http%25253A%25
252F%25252Ferrors.angularjs.org%25252F1.2.25%25252F%252524injector%25252
Fnomod%25253Fp0%25253Dpasvaz.bindonce%25250A%252520%252520%252520%252520
at%252520Error%252520(native)%25250A%252520%252520%252520%252520at%25252
0http%25253A%25252F%25252Flocalhost%25253A7357%25252Fvendor%25252Fangula
r%25252Fangular.min.js%25253A6%25253A450%25250A%252520%252520%252520%252
520at%252520http%25253A%25252F%25252Flocalhost%25253A7357%25252Fvendor%2
5252Fangular%25252Fangular.min.js%25253A20%25253A494%25250A%252520%25252
0%252520%252520at%252520http%25253A%25252F%25252Flocalhost%25253A7357%25
252Fvendor%25252Fangular%25252Fangular.min.js%25253A21%25253A502%25250A%
252520%252520%252520%252520at%252520http%25253A%25252F%25252Flocalhost%2
5253A7357%25252Fvendor%25252Fangular%25252Fangular.min.js%25253A33%25253
A267%25250A%252520%252520%252520%252520at%252520r%252520(http%25253A%252
52F%25252Flocalhost%25253A7357%25252Fvendor%25252Fangular%25252Fangular.
min.js%25253A7%25253A290)%25250A%252520%252520%252520%252520at%252520e%2
52520(http%25253A%25252F%25252Flocalhost%25253A7357%25252Fvendor%25252Fa
ngular%25252Fangular.min.js%25253A33%25253A207)%25250A%252520%252520%252
520%252520at%252520http%25253A%25252F%25252Flocalhost%25253A7357%25252Fv
endor%25252Fangular%25252Fangular.min.js%25253A33%25253A284%25250A%25252
似乎有一些明显的东西我错过了,但我不能完全掌握它。请注意,在代码块中删除beforeEach(inject());
和编写标准测试it
就像一个魅力。另外,如果我只是声明一个angular.module('myApp');
然后尝试module()
这样inject()
做,它工作正常。似乎我的模块定义中发生了一些事情,但应用程序本身运行良好,我可以说没有错误!
有人遇到这个或知道我应该调查什么吗?提前致谢!
编辑:
我认为如果我为我的问题提供一些背景信息可能会更有意义。我已经开发 Angular 应用程序几个星期了,而且由于没有进行单元测试,我已经有过好几次了。决定从现在开始进行 TDD,我设置了 Testem,编写了一个 .spec.js 文件并尝试开始。我没有测试任何现有的代码,这将在稍后出现,而只是尝试测试我正在使用的应用程序的一部分。在编写我的第一段代码或测试之前,仅根据文档设置 module() 和 inject() 调用就惨遭失败。这就是我现在的位置。