Unit Tests Fail after beta11 to beta12 update


#1

Hey

I have a stringe issue. I updated the ionic framework from beta11 to beta12, now a lot of my unit tests fail like this:

PhantomJS 1.9.7 (Mac OS X) Controller: xxxxCtrl should list connections FAILED
	Error: Unexpected request: GET views/xxx/yyyy/done.html
	Expected GET @@API_URL/xxx/yyy/endpoint
	    at $httpBackend (/Users/michu/_code/project/client/bower_components/angular-mocks/angular-mocks.js:1181)
	    at sendReq (/Users/michu/_code/project/client/bower_components/angular/angular.js:8355)
	    at /Users/michu/_code/project/client/bower_components/angular/angular.js:8087
	    at /Users/michu/_code/project/client/bower_components/angular/angular.js:11572
	    at /Users/michu/_code/project/client/bower_components/angular/angular.js:11572
	    at /Users/michu/_code/project/client/bower_components/angular/angular.js:11658
	    at /Users/michu/_code/project/client/bower_components/angular/angular.js:12701
	    at /Users/michu/_code/project/client/bower_components/angular/angular.js:12513
	    at /Users/michu/_code/project/client/bower_components/angular-mocks/angular-mocks.js:1440
	    at /Users/michu/_code/project/client/test/spec/controllers/xxxx/testname.js:35

If I downgrad to beta 11, those error disappears. are there any known issues with the beta12? or someone has some hints about this very strange issues?


#2

I’m getting this same issue when I upgraded from beta11 to beta13 (I skipped 12). As a work around, I’m injecting $httpBackend into my tests and setting up every possible request…

    $httpBackend.when('GET', 'callSupport/callSupport.html').respond({});
    $httpBackend.when('GET', 'config/config.html').respond({});
    $httpBackend.when('GET', 'tabs/tabs.html').respond({});
    //Etc

or

    $httpBackend.when('GET',new RegExp( '.*')).respond({}); //Using Regex

This allows my tests to pass, but it’s really ugly. I think every template is trying to be reached, which causes a request to fire, which will fail in unit tests.


#3

Yeah this error is really annoying. I believe it’s caused by the templateCache feature added in beta.12.

templateCache: automatically cache template files to prevent flicker on page navigation and imp (944a92b0)

@MrOnosa, your workaround with the RegExp is fantastic. I was worried I was going to have to list out every route. I’m hoping we’ll have a cleaner fix to this in the future.