mardi 3 mai 2016

Angular: $httpBackend expectPOST response data 'undefined' for http status codes = 4XX

I recently upgraded from angular 1.5.0 to 1.5.5 and now I've the following problem I could not find an answer for:

// Mocha tests with sinon
...
// this works fine!
// console dump: { foo: 'bar' }
$httpBackend.expectPOST(authorizeUrl, {}).respond(200, { foo: 'bar' });

AuthService.login(credentials)
    .then(function successCallback(response) {
        dump(angular.mock.dump(response.data));
    }, function errorCallback(response) {
        sinon.assert.fail(error);
    });

// this is not working, because 'response' is undefined
// error: undefined is not an object (evaluating 'response.data')
$httpBackend.expectPOST(authorizeUrl, {}).respond(400, { error: 'bad request' });

AuthService.login(credentials)
    .then(function successCallback(response) {
        sinon.assert.fail(error);
    }, function errorCallback(response) {
        dump(angular.mock.dump(response.data));
    });

I tried to figure out what exactly changed from angular 1.5.0 to 1.5.5, but I could find any correlations ... what am I missing?

Update: Seems like $http is the problem. I tried:

$http
    .post(...)
    .then(function successCallback(response) {
        window.console.log(response);
    }, function errorCallback(response) {
        // reponse is 'undefined'!
        window.console.log(response);
    });

Aucun commentaire:

Enregistrer un commentaire