My Angular 1.3 application uses the angular translation library . In my Karma tests, I try to make fun of the $translate provider with the Mock object I created.
The layout object is called MockTranslate and belongs to the myMocks module. I do not include the source for MockTranslate in the question since it is not relevant to the question.
My test topic is the controller, and I can easily make fun of $translate using the following:
module('myMocks'); inject(function($controller, MockTranslate) { $controller("MyController", { $translate: MockTranslate.create(translations); }); });
The above is ridiculous work, however my preference would be to mock the provider using angular.mock.module with something like:
module('myMocks'); module("myModule", function($provide) { $provide.provider("$translate", function(MockTranslate) { return MockTranslate.create(translations); }); });
But I get the following error while running my tests:
Error: [$injector:modulerr] Failed to instantiate module function ($provide) due to: Error: [$injector:unpr] Unknown provider: MockTranslate
How do I mock a provider using angular.mock.module ?
source share