我的一个单元测试遇到了一些问题。我试图测试一个指令,我试图在单元测试中获取对$compile提供程序的引用。我正在使用grunt和一个名为grunt-contrib-testem的特定包来执行所有单元测试。
这是此类插件(咖啡脚本)的配置片段
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(inject(function(_$compile_, _$rootScope_) {
$compile = _$compile_;
$rootScope = _$rootScope_;
}