Juri Juri - 2 months ago 24
AngularJS Question

Jasmine test error on Jenkins Build Server with angular-mocks?

I'm unit testing a angular directive with Angular and Jasmine.
Mocking the http backend works fine and all tests working fine locally. But on the build server i get:

Error: Unexpected request: GET app/auth/views/login.html
No more request expected (line 1419)

My test setup:


beforeEach(() => {
inject(function ($injector, _$compile_, _$rootScope_) {
// The injector unwraps the underscores (_) from around the parameter names when matching
$compile = _$compile_;
$rootScope = _$rootScope_;
$httpBackend = $injector.get("$httpBackend");

$httpBackend.whenGET("api/langs/gb.json").respond({ "COMMON.HOME": homeName });

$httpBackend.whenGET("app/home/views/dashboard.html").respond(200, "");
$httpBackend.whenGET("app/home/views/login.html").respond(200, "");

directiveElem = getCompiledElement();

What is different on the build server. I can't explain this behavior.


UI-Router is attempting to load the app/auth/views/login.html file during your app startup.

If you run the Jasmine tests locally, you already have a web server setup at a url like http://localhost, so the request for http://localhost/app/auth/views/login.html will return the actual file. When you run this test on the build server, the build server is not configured to serve the http://localhost/app/auth/views/login.html url, so it returns a 404.

Here is an article describing how to work around that issue: UI-router interfers with $httpbackend unit test, angular js

Also, here's a github issue that goes into more detail about how to deal with this: https://github.com/angular-ui/ui-router/issues/212