2014-01-15 144 views
0

我在单元测试中遇到了一些问题。我试图测试一个指令,并试图获得对单元测试中$ 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 

非常感谢。

+0

你可能不需要手动调用注射器。我可以写beforeEach(注入(函数($ rootScope,$ compile){ - 但这不是错误的原因。)你仔细检查,angular-mocks.js可用吗? – michael

+0

我缺少的是一条线例如:beforeEach(module('myApp')); – michael

+0

对不起beforeEach(module(“myApp”));包括让我编辑帖子 –

回答

0

尝试注入他们这样

beforeEach(inject(function(_$compile_, _$rootScope_) { 
    $compile = _$compile_; 
    $rootScope = _$rootScope_; 
} 
+0

这种方法也没有效果... –

+0

你有什么错误吗? – dcodesmith

+0

同上:[$ injector:unpr]未知提供者:$ windowsProvider < - $ windows < - $ http < - $ compile –