I am designing the unit tests for an AngularJS web app, using Karma-Jasmine. The web app uses angular-translate and, specifically, employs the $translatePartialLoaderProvider module. The app itself works well; however, the unit tests fail with the following error:
Error: [$injector:modulerr] Failed to instantiate module myApp.view1 due to:
[$injector:unpr] Unknown provider: $translatePartialLoaderProvider
I have followed the unit-testing instructions for angular-translate available at http://angular-translate.github.io/docs/#/guide/22_unit-testing-with-angular-translate, as mentioned in Question #18876290, yet the unit tests still fail with the above-mentioned error.
A code sample illustrating the error is available here (Plunker): http://embed.plnkr.co/8X7diP/. Note that the app works well: you can switch views and the view text is translated as expected. As soon as you remove $translatePartialLoaderProvider in view1mod.js, the app passes the test.
Your help would be greatly appreciated!
Its because, even though your app.js
has the translate
dependency, your view1
or view2
modules don't, i.e. this will fix the spec -
angular.module('myApp.view1', ['ngRoute', 'pascalprecht.translate'])
You'll have to fix this in both view1mod.js
and view2mod.js
.