我正在尝试在我的过滤器' manufacturerFilter'上运行Angular测试。
describe('productApp', function() {
var manufacturerFilter;
beforeEach(function() {
module('productApp', ['ui.bootstrap']);
});
beforeEach(inject(function(_$filter_) {
manufacturerFilter = _$filter_('manufacturerFilter');
}));
it('has a manufacturerFilter filter', function() {
expect(manufacturerFilter.not.toBeNull());
});
});
收到以下错误:
Error: [$injector:modulerr] http:// errors.angularjs.org/1.3.0-rc.0/$injector/modulerr?p0=ui.bootstrap&p1=Error%3A%20%5Bng%3Aareq%5D%20http%3A%2F%2Ferrors.angularjs.org%2F1.3.0-rc.0%2Fng%2Fareq%3Fp0%3Dfn%26p1%3Dnot%2520a%2520function%252C%2520got%2520string%0A%20%20%20%20at%20Error%20(native)%0A%20%20%20%20at%20https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.3.0-rc.0%2Fangular.min.js%3A6%3A421%0A%20%20%20%20at%20Jb%20(https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.3.0-rc.0%2Fangular.min.js%3A19%3A466)%0A%20%20%20%20at%20kb%20(https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.3.0-rc.0%2Fangular.min.js%3A20%3A47)%0A%20%20%20%20at%20Rb%20(https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.3.0-rc.0%2Fangular.min.js%3A33%3A93)%0A%20%20%20%20at%20Object.e%20%5Bas%20invoke%5D%20(https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.3.0-rc.0%2Fangular.min.js%3A35%3A142)%0A%20%20%20%20at%20https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.3.0-rc.0%2Fangular.min.js%3A34%3A192%0A%20%20%20%20at%20r%20(https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.3.0-rc.0%2Fangular.min.js%3A7%3A296)%0A%20%20%20%20at%20f%20(https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.3.0-rc.0%2Fangular.min.js%3A33%3A419)%0A%20%20%20%20at%20Object.Hb%20%5Bas%20injector%5D%20(https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.3.0-rc.0%2Fangular.min.js%3A37%3A99)
App:
var myApp = angular.module('productApp', ['ui.bootstrap']);
过滤:
myApp.filter('manufacturerFilter', function() {
return function(input, $scope) {
// filter code
}
});
这在以前工作过,但在添加了一些代码后,主要依赖于ui-bootstrap,测试并没有失败。执行似乎甚至无法达到断言,但在注入过滤器时失败了?
答案 0 :(得分:0)
尝试像这样运行:
describe('productApp', function() {
var manufacturerFilter;
beforeEach(function() {
module('productApp');
inject(function(_$filter_) {
manufacturerFilter = _$filter_('manufacturerFilter');
});
});
it('has a manufacturerFilter filter', function() {
expect(manufacturerFilter.not.toBeNull());
});
});