Reputation: 497
I'm using an Angular service in an AngularJS module downgraded using downgradeInjectible. The app is working fine with the downgraded service but all my unit tests are failing with the below error:
Error: Error while instantiating injectable 'MyAngularService': Not a valid '@angular/upgrade' application. Did you forget to downgrade an Angular module or include it in the AngularJS application?
Do I need to use downgradeInjectable again in my karma test setup to configure this service for unit tests?
I was testing the below code to downgrade the service in test setup but I don't think it's the right approach.
// downgrade service for unit tests
beforeEach(angular.mock.module('myModule').factory('MyAngularService',downgradeInjectable(MyAngularService) as any))
Any advice on how to resolve this issue?
Upvotes: 2
Views: 1033
Reputation: 159
Bit late to the party, but I just figured this out. You can do
angular.mock.module(($provide: ng.auto.IProvideService) => {
$provide.value("MyAngularService", myAngularServiceMock));
});
as part of the beforeEach
in your tests. This way you'd provide a previously created mock instance of myAngularServiceMock
as the expected MyAngularService
.
Upvotes: 2