mardi 29 mars 2016

Gulp test fails

When I try to do a gulp test, this is what happens

Error: spyOn could not find an object to spy upon for logout()
        at /workspace/WebServices/src/test/javascript/spec/components/auth/auth.services.spec.js:9
    TypeError: 'undefined' is not an object (evaluating '$httpBackend.verifyNoOutstandingExpectation')
        at /workspace/WebServices/src/test/javascript/spec/components/auth/auth.services.spec.js:9
PhantomJS 1.9.8 (Linux 0.0.0): Executed 53 of 53 (53 FAILED) (0 secs / 0.776 secs)
PhantomJS 1.9.8 (Linux 0.0.0): Executed 53 of 53 (53 FAILED) ERROR (1 min 8.425 secs / 0.776 secs)
[20:17:05] 'test' errored after 1.23 min

Any idea whats going on here?

Code in the file

'use strict';

describe('Service Tests', function () {
    beforeEach(mockI18nCalls);
    beforeEach(mockScriptsCalls);

    describe('Auth', function () {
        var $httpBackend, spiedLocalStorageService, authService, spiedAuthServerProvider;

        beforeEach(inject(function($injector, localStorageService, Auth, AuthServerProvider) {
            $httpBackend = $injector.get('$httpBackend');
            spiedLocalStorageService = localStorageService;
            authService = Auth;
            spiedAuthServerProvider = AuthServerProvider;

            $httpBackend.expectPOST(/api\/logout\?cacheBuster=\d+/).respond(200, '');
        }));
        //make sure no expectations were missed in your tests.
        //(e.g. expectGET or expectPOST)
        afterEach(function() {
            $httpBackend.verifyNoOutstandingExpectation();
            $httpBackend.verifyNoOutstandingRequest();
        });

        it('should call backend on logout then call authServerProvider.logout', function(){
            //GIVEN
            //Set spy
            spyOn(spiedAuthServerProvider, 'logout').and.callThrough();
            spyOn(spiedLocalStorageService, "clearAll").and.callThrough();

            //WHEN
            authService.logout();
            //flush the backend to "execute" the request to do the expectedGET assertion.
            $httpBackend.flush();

            //THEN
            expect(spiedAuthServerProvider.logout).toHaveBeenCalled();
            expect(spiedLocalStorageService.clearAll).toHaveBeenCalled();
        });

    });
});

Aucun commentaire:

Enregistrer un commentaire