我有一个常量的以下服务:
angular.module('app',[]).constant('alertType',{
success:1,
error:0
})
.factory("dataService",dataService);
dataService.$inject = ['$timeout', 'alertType']
function dataService($timeout, alertType) {
return {
//some code related to the service
}
}
以下是检查服务是否已注册的服务的测试用例
describe('Testing "dataService" service', function() {
var _dataService;
beforeEach(function() {
module('app');
inject(function(dataService) {
_dataService = dataService;
});
});
it('Should be registered', function() {
expect(_dataService).toBeDefined();
});
});
由于某种原因,它不起作用。我得到一个很长的错误,看起来像这样:
错误:[$ injector:unpr]未知提供者:dataServiceProvider< - dataService http://errors.angularjs.org/1.3.0/ $ injector / unpr?p0 = dataServiceProvider%20%3C-%20dataService
我做对了还是有什么问题?
答案 0 :(得分:0)
尝试在描述块的顶部模拟您的提供程序,如下所示:
beforeEach(module($provide => {
$provide.constant('alertType',{
success: 1,
error: 0
});
}));
有关详细信息,请参阅此答案:Unknown Provider when unit testing filter