我在单元测试中遇到了一些问题。我试图测试一个指令,并试图获得对单元测试中$ compile提供者的引用。我使用grunt与一个名为grunt-contrib-testem的特定包执行所有单元测试。单元测试指令
这里的是这样的插件(coffescript)
testem:
unit:
src: [
"angular.js"
"angular-mocks.js"
"app.js"
"directive.js"
"spec.js"
]
options:
launch_in_dev: ["PhantomJS"]
debug: true
配置的片段和测试用例的一个片段:
beforeEach(module("myapp"));
beforeEach(inject(function($injector){
rootScope = $injector.get("$rootScope");
compile = $injector.get("$compile"); //<-here is the problem
}));
而且我看到错误消息如下:
[$injector:unpr] Unknown provider: $windowsProvider <- $windows <- $http <- $compile
非常感谢。
你可能不需要手动调用注射器。我可以写beforeEach(注入(函数($ rootScope,$ compile){ - 但这不是错误的原因。)你仔细检查,angular-mocks.js可用吗? – michael
我缺少的是一条线例如:beforeEach(module('myApp')); – michael
对不起beforeEach(module(“myApp”));包括让我编辑帖子 –