在AngularJS单元测试中找不到模块错误 [英] Module not found error in AngularJS unit test
问题描述
我试着用Karma / Jasmine进行一个非常简单的测试,来测试我的AngularJS应用程序。这似乎工作
beforeEach(
module('myApp')
);
$ b $ it('blah',function(){
expect(true).toBe(true);
});
虽然这并不是
beforeEach(
function(){
module('myApp')
}
);
$ b $ it('blah',function(){
expect(true).toBe(true);
});
我希望能够在每个测试套件之前做其他的事情,但它不会给我任何有意义的错误为了能够调试它,我看到的只有一个是:
pre $ TypeError:'undefined'不是一个对象(评估'currentSpec .queue.running')
与在beforeEach构造中调用该函数的行相关第二个例子。
我希望别人遇到过这种情况,可以提供帮助吗?
感谢
Stephen
申报你的模块。如果你想做更多的事情,你可以使用beforeEach。
例如:
var scope;
var ctrl;
var mysvcMock;
beforeEach(module('myApp'));
beforeEach(function(){
mysvcMock = {
};
});
beforeEach(inject(function($ rootScope,$ controller){$ b $ scope = $ rootScope。$ new();
ctrl = $ controller('MyController',{
$ scope:scope,
mysvc:mysvcMock
});
}));
//它检查
让我知道您是否需要更清晰这和我可以为你一个小提琴。
谢谢,
约旦
I'm trying a very simple test with Karma/Jasmine, to unit test my AngularJS app. This seems to work
beforeEach(
module('myApp')
);
it('should blah', function () {
expect(true).toBe(true);
});
while this doesnt
beforeEach(
function () {
module('myApp')
}
);
it('should blah', function () {
expect(true).toBe(true);
});
I want to be able to do other stuff beforeEach test suite, but it's not giving me any meaningful errors to be able to debug it, the only one I see is
TypeError: 'undefined' is not an object (evaluating 'currentSpec.queue.running')
relating to the line where the function is called within the beforeEach construct in the second example.
Im hoping someone else has come across this and can assist?
Thanks Stephen
Thats just how you declare your module. If you want to do more you can just use an additional beforeEach.
For Example:
var scope;
var ctrl;
var mysvcMock;
beforeEach(module('myApp'));
beforeEach(function() {
mysvcMock = {
};
});
beforeEach(inject(function($rootScope, $controller) {
scope = $rootScope.$new();
ctrl = $controller('MyController', {
$scope: scope,
mysvc: mysvcMock
});
}));
//it checks
Let me know if you need more clarity on this and I can put together a fiddle for you.
Thanks,
Jordan
这篇关于在AngularJS单元测试中找不到模块错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!