Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jasmine Controller test: $timeout.flush() causes an 'Unexpected GET request' error

I have the following test:

it('should load productGroups into the scope', function(){
  scope._section = 'modifiers';
  scope.userData = {method: 'manual'};
  scope.$digest();
  timeout.flush();//causes the error

  expect(scope.productGroups).toEqual(productGroupService.getProductGroups());
});

Now, the action that I am trying to test occurs within a timeout of 0, because of some issues I had with syncing the data stored in the cookies.

Now, without the marked line, the test runs find, except the expected result is not obtained. With the marked line, I get the following error:

    Error: Unexpected request: GET views/main.html
    No more request expected
        at $httpBackend (/home/oleg/dev/vita-webapp-new/bower_components/angular-mocks/angular-mocks.js:1178:9)
        at sendReq (/home/oleg/dev/vita-webapp-new/bower_components/angular/angular.js:8180:9)
        at $http.serverRequest (/home/oleg/dev/vita-webapp-new/bower_components/angular/angular.js:7921:16)
        at wrappedCallback (/home/oleg/dev/vita-webapp-new/bower_components/angular/angular.js:11319:81)
        at wrappedCallback (/home/oleg/dev/vita-webapp-new/bower_components/angular/angular.js:11319:81)
        at /home/oleg/dev/vita-webapp-new/bower_components/angular/angular.js:11405:26
        at Scope.$eval (/home/oleg/dev/vita-webapp-new/bower_components/angular/angular.js:12412:28)
        at Scope.$digest (/home/oleg/dev/vita-webapp-new/bower_components/angular/angular.js:12224:31)
        at Scope.$apply (/home/oleg/dev/vita-webapp-new/bower_components/angular/angular.js:12516:24)
        at Object.fn (/home/oleg/dev/vita-webapp-new/bower_components/angular/angular.js:14023:36)


Process finished with exit code 0

main.html, is obviously the view of this controller, tried placing it in templateCache with the following code, but it did not help:

$templateCache.put('views/main.html', $templateCache.get('app/views/views/main.html'));

Any assistance would be much appreciated.

like image 568
Oleg Belousov Avatar asked Oct 21 '22 02:10

Oleg Belousov


1 Answers

Solution I've been able to come up with is:

$httpBackend.when('GET', 'views/main.html').respond('');

in the beforeEach function

Nothing else doesn't seem to work.

While it's a working solution for unit-testing purposes, it would never work for an E2E test.

like image 53
Oleg Belousov Avatar answered Oct 27 '22 16:10

Oleg Belousov