angular.js/test/service/xhr.errorSpec.js
Misko Hevery 48697a2b86 refactor(injector): turn scope into a service
- turn scope into a $rootScope service.
- injector is now a starting point for creating angular application.
- added inject() method which wraps jasmine its/beforeEach/afterEach,
  and which allows configuration and injection of services.
- refactor tests to use inject() where possible

BREAK:
- removed angular.scope() method
2011-11-14 16:39:31 -08:00

31 lines
903 B
JavaScript

'use strict';
describe('$xhr.error', function() {
var log;
beforeEach(inject(function(service) {
service('$xhr.error', function(){
return jasmine.createSpy('$xhr.error');
});
service.alias('$xhr.error', '$xhrError');
log = '';
}));
function callback(code, response) {
expect(code).toEqual(200);
log = log + toJson(response) + ';';
}
it('should handle non 200 status codes by forwarding to error handler', inject(function($browser, $xhr, $xhrError) {
$browser.xhr.expectPOST('/req', 'MyData').respond(500, 'MyError');
$xhr('POST', '/req', 'MyData', callback);
$browser.xhr.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'});
}));
});