mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-05-09 03:58:12 +08:00
fix($resource): properly call error callback when resource is called with two arguments
This commit is contained in:
@@ -244,22 +244,35 @@ describe("resource", function() {
|
||||
|
||||
describe('failure mode', function() {
|
||||
var ERROR_CODE = 500,
|
||||
ERROR_RESPONSE = 'Server Error';
|
||||
ERROR_RESPONSE = 'Server Error',
|
||||
errorCB;
|
||||
|
||||
beforeEach(function() {
|
||||
xhr.expectGET('/CreditCard/123').respond(ERROR_CODE, ERROR_RESPONSE);
|
||||
errorCB = jasmine.createSpy();
|
||||
});
|
||||
|
||||
it('should report error when non 2xx if error callback is not provided', function() {
|
||||
xhr.expectGET('/CreditCard/123').respond(ERROR_CODE, ERROR_RESPONSE);
|
||||
CreditCard.get({id:123});
|
||||
xhr.flush();
|
||||
expect($xhrErr).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should call the error callback if provided on non 2xx response', function() {
|
||||
CreditCard.get({id:123}, noop, callback);
|
||||
xhr.expectGET('/CreditCard/123').respond(ERROR_CODE, ERROR_RESPONSE);
|
||||
CreditCard.get({id:123}, callback, errorCB);
|
||||
xhr.flush();
|
||||
expect(callback).toHaveBeenCalledWith(500, ERROR_RESPONSE);
|
||||
expect(errorCB).toHaveBeenCalledWith(500, ERROR_RESPONSE);
|
||||
expect(callback).not.toHaveBeenCalled();
|
||||
expect($xhrErr).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should call the error callback if provided on non 2xx response', function() {
|
||||
xhr.expectGET('/CreditCard').respond(ERROR_CODE, ERROR_RESPONSE);
|
||||
CreditCard.get(callback, errorCB);
|
||||
xhr.flush();
|
||||
expect(errorCB).toHaveBeenCalledWith(500, ERROR_RESPONSE);
|
||||
expect(callback).not.toHaveBeenCalled();
|
||||
expect($xhrErr).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user