Unit testing 在Jasmine测试中配置Angular service provider
我在我的Unit testing 在Jasmine测试中配置Angular service provider,unit-testing,testing,angularjs,jasmine,Unit Testing,Testing,Angularjs,Jasmine,我在我的someModule模块上有一项服务: someModule.provider('someService', function() { this.options = {}; this.$get = function () { return options; }; }); 我正在编写规范,目前为止我有以下几点: beforeEach(mocks.module('directives', ['someModule'])); beforeEach(f
someModule
模块上有一项服务:
someModule.provider('someService', function() {
this.options = {};
this.$get = function () {
return options;
};
});
我正在编写规范,目前为止我有以下几点:
beforeEach(mocks.module('directives', ['someModule']));
beforeEach(function () {
directives.config(function (someServiceProvider) {
someServiceProvider.options({ foo: 'bar' });
});
});
在我的规范中的每个测试之前,我需要配置我的someService
服务。但是,以下代码会产生错误:错误:未知提供程序:someServiceProvider
我做错了什么?我认为,如果我需要一个模块,那么该模块上可用的任何提供者都将被“继承”?如何在此测试中配置my
someService
服务中的选项?当您调用配置函数时,您的模块处于运行阶段。此时,您不能再注入提供程序。尝试移动已注入某个ServiceProvider的函数
beforeEach(module('myModule', function(someProvider) {
someProvider.configure(1);
}));
it('should work now', inject(function(some) {
expect(some.func()).toBeAvailable();
}));