diff --git a/src/Browser.js b/src/Browser.js index b10c43cf34ca..31f2c7f3ad19 100644 --- a/src/Browser.js +++ b/src/Browser.js @@ -113,7 +113,9 @@ function Browser(window, document, body, XHR, $log) { }); xhr.onreadystatechange = function() { if (xhr.readyState == 4) { - completeOutstandingRequest(callback, xhr.status || 200, xhr.responseText); + // normalize IE bug (http://bugs.jquery.com/ticket/1450) + var status = xhr.status == 1223 ? 204 : xhr.status || 200; + completeOutstandingRequest(callback, status, xhr.responseText); } }; xhr.send(post || ''); diff --git a/test/BrowserSpecs.js b/test/BrowserSpecs.js index 45fb0ed9270c..635909a739c5 100644 --- a/test/BrowserSpecs.js +++ b/test/BrowserSpecs.js @@ -59,18 +59,18 @@ describe('browser', function(){ it('should process callbacks immedietly with no outstanding requests', function(){ var callback = jasmine.createSpy('callback'); browser.notifyWhenNoOutstandingRequests(callback); - expect(callback).wasCalled(); + expect(callback).toHaveBeenCalled(); }); it('should queue callbacks with outstanding requests', function(){ var callback = jasmine.createSpy('callback'); browser.xhr('GET', '/url', null, noop); browser.notifyWhenNoOutstandingRequests(callback); - expect(callback).not.wasCalled(); + expect(callback).not.toHaveBeenCalled(); xhr.readyState = 4; xhr.onreadystatechange(); - expect(callback).wasCalled(); + expect(callback).toHaveBeenCalled(); }); }); @@ -83,7 +83,7 @@ describe('browser', function(){ log += code + ':' + data + ';'; }); browser.notifyWhenNoOutstandingRequests(callback); - expect(callback).not.wasCalled(); + expect(callback).not.toHaveBeenCalled(); expect(scripts.length).toEqual(1); var script = scripts[0]; script.remove = function(){ @@ -93,7 +93,7 @@ describe('browser', function(){ expect(url[0]).toEqual('http://example.org/path'); expect(typeof fakeWindow[url[1]]).toEqual($function); fakeWindow[url[1]]('data'); - expect(callback).wasCalled(); + expect(callback).toHaveBeenCalled(); expect(log).toEqual('remove();200:data;'); expect(typeof fakeWindow[url[1]]).toEqual('undefined'); }); @@ -124,6 +124,19 @@ describe('browser', function(){ expect(response).toEqual('RESPONSE'); }); + it('should normalize IE\'s 1223 status code into 204', function() { + var callback = jasmine.createSpy('XHR'); + + browser.xhr('GET', 'URL', 'POST', callback); + + xhr.status = 1223; + xhr.readyState = 4; + xhr.onreadystatechange(); + + expect(callback).toHaveBeenCalled(); + expect(callback.argsForCall[0][0]).toEqual(204); + }); + it('should not set Content-type header for GET requests', function() { browser.xhr('GET', 'URL', 'POST-DATA', function(c, r) {}); @@ -159,10 +172,10 @@ describe('browser', function(){ it('should update outstandingRequests counter', function() { var callback = jasmine.createSpy('callback'); browser.defer(callback); - expect(callback).not.wasCalled(); + expect(callback).not.toHaveBeenCalled(); fakeSetTimeout.flush(); - expect(callback).wasCalled(); + expect(callback).toHaveBeenCalled(); }); }); diff --git a/test/JsonSpec.js b/test/JsonSpec.js index 4a1609050d14..2067d88f0043 100644 --- a/test/JsonSpec.js +++ b/test/JsonSpec.js @@ -140,10 +140,10 @@ describe('json', function(){ var spy = this.spyOn(JSON, 'parse').andCallThrough(); expect(fromJson('{}')).toEqual({}); - expect(spy).wasNotCalled(); + expect(spy).not.toHaveBeenCalled(); expect(fromJson('{}', true)).toEqual({}); - expect(spy).wasCalled(); + expect(spy).toHaveBeenCalled(); }); diff --git a/test/ResourceSpec.js b/test/ResourceSpec.js index fe6c3fdf0e63..127af4ba7082 100644 --- a/test/ResourceSpec.js +++ b/test/ResourceSpec.js @@ -78,10 +78,10 @@ describe("resource", function() { var cc = CreditCard.save({name:'misko'}, callback); nakedExpect(cc).toEqual({name:'misko'}); - expect(callback).wasNotCalled(); + expect(callback).not.toHaveBeenCalled(); xhr.flush(); nakedExpect(cc).toEqual({id:123, name:'misko'}); - expect(callback).wasCalledWith(cc); + expect(callback).toHaveBeenCalledWith(cc); }); it("should read resource", function(){ @@ -89,10 +89,10 @@ describe("resource", function() { var cc = CreditCard.get({id:123}, callback); expect(cc instanceof CreditCard).toBeTruthy(); nakedExpect(cc).toEqual({}); - expect(callback).wasNotCalled(); + expect(callback).not.toHaveBeenCalled(); xhr.flush(); nakedExpect(cc).toEqual({id:123, number:'9876'}); - expect(callback).wasCalledWith(cc); + expect(callback).toHaveBeenCalledWith(cc); }); it("should read partial resource", function(){ @@ -106,7 +106,7 @@ describe("resource", function() { expect(cc.number).not.toBeDefined(); cc.$get(callback); xhr.flush(); - expect(callback).wasCalledWith(cc); + expect(callback).toHaveBeenCalledWith(cc); expect(cc.number).toEqual('9876'); }); @@ -115,7 +115,7 @@ describe("resource", function() { var cc = CreditCard.save({id:{key:123}, name:'misko'}, callback); nakedExpect(cc).toEqual({id:{key:123}, name:'misko'}); - expect(callback).wasNotCalled(); + expect(callback).not.toHaveBeenCalled(); xhr.flush(); }); @@ -124,10 +124,10 @@ describe("resource", function() { var ccs = CreditCard.query({key:'value'}, callback); expect(ccs).toEqual([]); - expect(callback).wasNotCalled(); + expect(callback).not.toHaveBeenCalled(); xhr.flush(); nakedExpect(ccs).toEqual([{id:1}, {id:2}]); - expect(callback).wasCalledWith(ccs); + expect(callback).toHaveBeenCalledWith(ccs); }); it("should have all arguments optional", function(){ @@ -143,14 +143,14 @@ describe("resource", function() { xhr.expectDELETE("/CreditCard/123").respond(200, {}); CreditCard.remove({id:123}, callback); - expect(callback).wasNotCalled(); + expect(callback).not.toHaveBeenCalled(); xhr.flush(); nakedExpect(callback.mostRecentCall.args).toEqual([{}]); callback.reset(); xhr.expectDELETE("/CreditCard/333").respond(204, null); CreditCard.remove({id:333}, callback); - expect(callback).wasNotCalled(); + expect(callback).not.toHaveBeenCalled(); xhr.flush(); nakedExpect(callback.mostRecentCall.args).toEqual([{}]); }); @@ -181,7 +181,7 @@ describe("resource", function() { nakedExpect(cc).toEqual({name:'misko'}); xhr.flush(); nakedExpect(cc).toEqual({id:123}); - expect(callback).wasCalledWith(cc); + expect(callback).toHaveBeenCalledWith(cc); }); it('should not mutate the resource object if response contains no body', function(){ diff --git a/test/ScopeSpec.js b/test/ScopeSpec.js index ab1ba124ebfd..da9c517e3cc6 100644 --- a/test/ScopeSpec.js +++ b/test/ScopeSpec.js @@ -62,7 +62,7 @@ describe('scope/model', function(){ var onEval = jasmine.createSpy('onEval'); model.$onEval(onEval); model.$eval(''); - expect(onEval).wasNotCalled(); + expect(onEval).not.toHaveBeenCalled(); }); it('should ignore none string/function', function(){ diff --git a/test/ValidatorsSpec.js b/test/ValidatorsSpec.js index 773ac7d0e0ac..4e4592bf0860 100644 --- a/test/ValidatorsSpec.js +++ b/test/ValidatorsSpec.js @@ -131,10 +131,10 @@ describe('ValidatorTest', function(){ var spy = jasmine.createSpy(); asynchronous.call(self, "kai", spy); - expect(spy).wasNotCalled(); + expect(spy).not.toHaveBeenCalled(); asynchronous.call(self, "misko", spy); - expect(spy).wasCalled(); + expect(spy).toHaveBeenCalled(); }); it("should ignore old callbacks, and not remove spinner", function(){ @@ -156,7 +156,7 @@ describe('ValidatorTest', function(){ scope.updateFn = jasmine.createSpy(); scope.name = 'misko'; scope.$eval(); - expect(scope.asyncFn).wasCalledWith('misko', scope.asyncFn.mostRecentCall.args[1]); + expect(scope.asyncFn).toHaveBeenCalledWith('misko', scope.asyncFn.mostRecentCall.args[1]); assertTrue(scope.$element.hasClass('ng-input-indicator-wait')); scope.asyncFn.mostRecentCall.args[1]('myError', {id: 1234, data:'data'}); assertFalse(scope.$element.hasClass('ng-input-indicator-wait')); diff --git a/test/service/deferSpec.js b/test/service/deferSpec.js index 8ac1b8030d0f..bd8fe7d7d0c3 100644 --- a/test/service/deferSpec.js +++ b/test/service/deferSpec.js @@ -43,10 +43,10 @@ describe('$defer', function() { var eval = this.spyOn(scope, '$eval').andCallThrough(); $defer(function() {}); - expect(eval).wasNotCalled(); + expect(eval).not.toHaveBeenCalled(); $browser.defer.flush(); - expect(eval).wasCalled(); + expect(eval).toHaveBeenCalled(); eval.reset(); //reset the spy; @@ -61,10 +61,10 @@ describe('$defer', function() { var eval = this.spyOn(scope, '$eval').andCallThrough(); $defer(function() {throw "Test Error";}); - expect(eval).wasNotCalled(); + expect(eval).not.toHaveBeenCalled(); $browser.defer.flush(); - expect(eval).wasCalled(); + expect(eval).toHaveBeenCalled(); }); it('should allow you to specify the delay time', function(){ diff --git a/test/service/xhr.bulkSpec.js b/test/service/xhr.bulkSpec.js index 89429a915bcd..2990e6662129 100644 --- a/test/service/xhr.bulkSpec.js +++ b/test/service/xhr.bulkSpec.js @@ -57,10 +57,10 @@ describe('$xhr.bulk', function() { $xhrBulk.flush(function(){ log += 'DONE';}); $browserXhr.flush(); - expect($xhrError).wasCalled(); + expect($xhrError).toHaveBeenCalled(); var cb = $xhrError.mostRecentCall.args[0].callback; expect(typeof cb).toEqual($function); - expect($xhrError).wasCalledWith( + expect($xhrError).toHaveBeenCalledWith( {url:'/req1', method:'GET', data:null, callback:cb}, {status:404, response:'NotFound'}); diff --git a/test/service/xhr.cacheSpec.js b/test/service/xhr.cacheSpec.js index 0a0140a676e3..ecaebc3f4670 100644 --- a/test/service/xhr.cacheSpec.js +++ b/test/service/xhr.cacheSpec.js @@ -128,17 +128,17 @@ describe('$xhr.cache', function() { $browserXhr.expectGET('/url').respond('+'); cache('GET', '/url', null, callback); - expect(eval).wasNotCalled(); + expect(eval).not.toHaveBeenCalled(); $browserXhr.flush(); - expect(eval).wasCalled(); + expect(eval).toHaveBeenCalled(); eval.reset(); //reset the spy cache('GET', '/url', null, callback); - expect(eval).wasNotCalled(); + expect(eval).not.toHaveBeenCalled(); $browser.defer.flush(); - expect(eval).wasCalled(); + expect(eval).toHaveBeenCalled(); }); }); diff --git a/test/service/xhr.errorSpec.js b/test/service/xhr.errorSpec.js index da1b102ebded..bd9f7a92922a 100644 --- a/test/service/xhr.errorSpec.js +++ b/test/service/xhr.errorSpec.js @@ -29,7 +29,7 @@ describe('$xhr.error', function() { $browserXhr.flush(); var cb = $xhrError.mostRecentCall.args[0].callback; expect(typeof cb).toEqual($function); - expect($xhrError).wasCalledWith( + expect($xhrError).toHaveBeenCalledWith( {url:'/req', method:'POST', data:'MyData', callback:cb}, {status:500, body:'MyError'}); }); diff --git a/test/service/xhrSpec.js b/test/service/xhrSpec.js index 39bc1c6650b1..ebcd90d48c3b 100644 --- a/test/service/xhrSpec.js +++ b/test/service/xhrSpec.js @@ -60,7 +60,7 @@ describe('$xhr', function() { $xhr('GET', '/reqGET', null, function(){ throw "MyException"; }); $browserXhr.flush(); - expect($log.error).wasCalledWith("MyException"); + expect($log.error).toHaveBeenCalledWith("MyException"); });