forked from angular/angular.js
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathxhr.errorSpec.js
36 lines (29 loc) · 1022 Bytes
/
xhr.errorSpec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
describe('$xhr.error', function() {
var scope, $browser, $browserXhr, $xhr, $xhrError, log;
beforeEach(function(){
scope = angular.scope({}, angular.service, {
'$xhr.error': $xhrError = jasmine.createSpy('$xhr.error')
});
$browser = scope.$service('$browser');
$browserXhr = $browser.xhr;
$xhr = scope.$service('$xhr');
log = '';
});
afterEach(function(){
dealoc(scope);
});
function callback(code, response) {
expect(code).toEqual(200);
log = log + toJson(response) + ';';
}
it('should handle non 200 status codes by forwarding to error handler', function(){
$browserXhr.expectPOST('/req', 'MyData').respond(500, 'MyError');
$xhr('POST', '/req', 'MyData', callback);
$browserXhr.flush();
var cb = $xhrError.mostRecentCall.args[0].callback;
expect(typeof cb).toEqual($function);
expect($xhrError).toHaveBeenCalledWith(
{url:'/req', method:'POST', data:'MyData', callback:cb},
{status:500, body:'MyError'});
});
});