AngularJS + Testem + Jasmine:为什么inject()给出了$ injectorr错误?

时间:2014-10-01 17:31:17

标签: javascript angularjs jasmine testem

我正在使用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()调用就会失败。这就是我现在所处的位置。

1 个答案:

答案 0 :(得分:0)

好吧,我不应该对角度误差链接感到沮丧。如果你一直点击它们,我最终发现了一个我没有链接的子依赖项!如果有其他人发现自己在这个特殊的泡菜,我希望这有助于他们!我正在关闭我为了从公众中删除我的实时代码所做的那个。特别感谢PSL如此迅速地做出回应,并且非常愿意尝试理解我的问题。