我正在使用Testem和Jasmine来设置一个环境,以便在我的AngularJS应用程序中开始单元测试。一切都很好,直到我第一次尝试使用注射器。这就是我得到的:
test.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()调用就失败了。这就是我现在的处境。
好吧,我不应该对角度误差链接感到沮丧。如果你一直点击它们,我最终发现了一个我没有链接到的子依赖项!如果其他人发现自己陷入了这种困境,我希望这能帮助他们!我正在关闭我为从公众中删除我的实时代码而制作的插件。特别感谢PSL如此迅速地做出回应,并愿意尝试理解我的问题。