javascript - Angular $httpBackend.expectGET - respond with 409 status & custom statusText -


trying create $httpbackend.expectget in unit test return status of 409 , custom statustext of 'testphrase'.

looking @ angular docs (https://docs.angularjs.org/api/ngmock/service/$httpbackend) gives following example of returned:

{function([status,] data[, headers, statustext]) | function(function(method, url, data, headers)}

having trouble understanding how interpret above example.

my current code is:

      $httpbackend         .expectget('/example/url')         .respond(function () {           return ['409', ['testphrase'], {}];         }); 

the code i'm testing is:

  $http.get('/example/url').then(function (response) {       console.log('success, status ' + response.status);       console.log('success, statustext ' + response.statustext);   }, function(response) {       console.log('error, status ' + response.status);       console.log('error, statustext ' + response.statustext);     }   }); 

the output console receiving test is:

'error, status 409' 'error, statustext ' 

expected output is:

'error, status 409' 'error, statustext testphrase' 

the documentation says:

respond{function([status,] data[, headers, statustext]) | function(function(method, url, data, headers)} – respond method takes set of static data returned or function can return array containing response status (number), response data (string), response headers (object), , text status (string).

you're doing second option, passing function returns array. here's should work. status text 4th item. (for clarity, included optional function parameters.)

$httpbackend .expectget('/example/url') .respond(function (method, url, data, headers) {     return [409, 'response body', {}, 'testphrase']; }); 

Comments

Popular posts from this blog

php - render data via PDO::FETCH_FUNC vs loop -

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

The canvas has been tainted by cross-origin data in chrome only -