aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorVojta Jina2011-08-18 23:48:01 +0200
committerIgor Minar2011-11-30 11:03:42 -0500
commit5487bdb3d1c905fb9453644f7e290c75dcee14c1 (patch)
tree95c8dffbaf7cf228c1a9631378185d0bd52424e7 /test
parent3ae3ccf3dab95793c868d626a4560aacf3cae796 (diff)
downloadangular.js-5487bdb3d1c905fb9453644f7e290c75dcee14c1.tar.bz2
feat($browser.xhr): add timeout option to abort request
Timeouted request responds internal status code -1, which should be normalized into 0 by $xhr.
Diffstat (limited to 'test')
-rw-r--r--test/service/browserSpecs.js17
1 files changed, 17 insertions, 0 deletions
diff --git a/test/service/browserSpecs.js b/test/service/browserSpecs.js
index 05c1dec0..566ffb09 100644
--- a/test/service/browserSpecs.js
+++ b/test/service/browserSpecs.js
@@ -228,6 +228,23 @@ describe('browser', function() {
expect(browser.xhr('GET', '/url', null, noop)).toBe(xhr);
});
+ it('should abort request on timeout', function() {
+ var callback = jasmine.createSpy('done').andCallFake(function(status, response) {
+ expect(status).toBe(-1);
+ });
+
+ browser.xhr('GET', '/url', null, callback, {}, 2000);
+ xhr.abort = jasmine.createSpy('xhr.abort');
+
+ fakeWindow.setTimeout.flush();
+ expect(xhr.abort).toHaveBeenCalledOnce();
+
+ xhr.status = 0;
+ xhr.readyState = 4;
+ xhr.onreadystatechange();
+ expect(callback).toHaveBeenCalledOnce();
+ });
+
it('should be async even if xhr.send() is sync', function() {
// IE6, IE7 is sync when serving from cache
var xhr;