angular.js/test/service/xhr.errorSpec.js
Misko Hevery 8f0dcbab80 feat(scope): new and improved scope implementation
- Speed improvements (about 4x on flush phase)
- Memory improvements (uses no function closures)
- Break $eval into $apply, $dispatch, $flush
- Introduced $watch and $observe

Breaks angular.equals() use === instead of ==
Breaks angular.scope() does not take parent as first argument
Breaks scope.$watch() takes scope as first argument
Breaks scope.$set(), scope.$get are removed
Breaks scope.$config is removed
Breaks $route.onChange callback has not "this" bounded
2011-08-02 01:00:03 +02:00

38 lines
1 KiB
JavaScript

'use strict';
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].success;
expect(typeof cb).toEqual($function);
expect($xhrError).toHaveBeenCalledWith(
{url: '/req', method: 'POST', data: 'MyData', success: cb},
{status: 500, body: 'MyError'});
});
});