aboutsummaryrefslogtreecommitdiffstats
path: root/test/ng/httpBackendSpec.js
diff options
context:
space:
mode:
authorDavid Bennett2013-04-27 11:22:03 -0400
committerIgor Minar2013-05-20 14:15:04 -0700
commit9f4f5937112655a9881d3281da8e72035bc8b180 (patch)
treef6c9b19448ea5ddde11198b0e6d7a516e0b83d7b /test/ng/httpBackendSpec.js
parent27a8824b50aa78e9a082b4377ca09250382a8655 (diff)
downloadangular.js-9f4f5937112655a9881d3281da8e72035bc8b180.tar.bz2
feat($http): add support for aborting via timeout promises
If the timeout argument is a promise, abort the request when it is resolved. Implemented by adding support to $httpBackend service and $httpBackend mock service. This api can also be used to explicitly abort requests while keeping the communication between the deffered and promise unidirectional. Closes #1159
Diffstat (limited to 'test/ng/httpBackendSpec.js')
-rw-r--r--test/ng/httpBackendSpec.js38
1 files changed, 38 insertions, 0 deletions
diff --git a/test/ng/httpBackendSpec.js b/test/ng/httpBackendSpec.js
index da4fed16..c65ab2e1 100644
--- a/test/ng/httpBackendSpec.js
+++ b/test/ng/httpBackendSpec.js
@@ -117,6 +117,44 @@ describe('$httpBackend', function() {
});
+ it('should abort request on timeout promise resolution', inject(function($timeout) {
+ callback.andCallFake(function(status, response) {
+ expect(status).toBe(-1);
+ });
+
+ $backend('GET', '/url', null, callback, {}, $timeout(noop, 2000));
+ xhr = MockXhr.$$lastInstance;
+ spyOn(xhr, 'abort');
+
+ $timeout.flush();
+ expect(xhr.abort).toHaveBeenCalledOnce();
+
+ xhr.status = 0;
+ xhr.readyState = 4;
+ xhr.onreadystatechange();
+ expect(callback).toHaveBeenCalledOnce();
+ }));
+
+
+ it('should not abort resolved request on timeout promise resolution', inject(function($timeout) {
+ callback.andCallFake(function(status, response) {
+ expect(status).toBe(200);
+ });
+
+ $backend('GET', '/url', null, callback, {}, $timeout(noop, 2000));
+ xhr = MockXhr.$$lastInstance;
+ spyOn(xhr, 'abort');
+
+ xhr.status = 200;
+ xhr.readyState = 4;
+ xhr.onreadystatechange();
+ expect(callback).toHaveBeenCalledOnce();
+
+ $timeout.flush();
+ expect(xhr.abort).not.toHaveBeenCalled();
+ }));
+
+
it('should cancel timeout on completion', function() {
callback.andCallFake(function(status, response) {
expect(status).toBe(200);