I just included ngMock into my project because I need it for $httpBackend. I have a bunch of karma/jasmine tests setup, and after including ngMock, everything is breaking because of an error it causes:
PhantomJS 1.9.7 (Windows 7): Executed 0 of 41 SUCCESS (0 secs / 0 secs)
PhantomJS 1.9.7 (Windows 7) ERROR
Error: Unexpected request: GET home/home.html
No more request expected
at C:/dev/app/bower_components/angular-mocks/angular-mocks.js:1181
Seems that it doesn't like ngRoute/$routeProvider. Specifically it breaks on the otherwise/redirectTo statement. If I comment-out that section, the karma/jasmine tests work without error.
$routeProvider
.when('/home', angularAMD.route({
templateUrl: 'home/home.html',
controller: ''
}))
.otherwise({
redirectTo: '/home'
});
Notice, I am using angularAMD (for lazy loading), but even when I rewrite that section to use just {} without the angularAMD.route(), it still throws the same error. ie:
$routeProvider
.when('/home', {
templateUrl: 'home/home.html',
controller: ''
})
.otherwise({
redirectTo: '/home'
});
Any idea why ngMock doesn't like ngRoute? For now I've created a workaround where I skip the $routeProvider section while running karma/jasmine tests. But I'm trying to understand what is going on, am I not supposed to be setting $routeProvider during unit-testing at all (is that bad practice)?
[Edit:] Issues seem to appear in other segments as well. I'm running a test that includes a service which is loading a template, and it also throws an error:
Error: Unexpected request: GET components/modal/modal.html
No more request expected
at $httpBackend (C:/dev/app/bower_components/angular-mocks/angular-mocks.js:1181)
[Edit:] Seems to throw the error when I call $httpBackend.flush();
[Edit:] Great, found posts related to issue. Can't believe Google didn't show any relevant results when I searched. Solution: If you found yourself here from Google Results, take a look at these: post 1, post 2.
[Edit:] Couldn't get any of those solutions working with angularAMD. Any suggestions?