-
Notifications
You must be signed in to change notification settings - Fork 27.5k
Issue with canceling XHR request using promises - fixed #12525 #12657
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1308,7 +1308,7 @@ describe("resource", function() { | |
}); | ||
|
||
describe('resource', function() { | ||
var $httpBackend, $resource; | ||
var $httpBackend, $resource, $q; | ||
|
||
beforeEach(module(function($exceptionHandlerProvider) { | ||
$exceptionHandlerProvider.mode('log'); | ||
|
@@ -1319,6 +1319,7 @@ describe('resource', function() { | |
beforeEach(inject(function($injector) { | ||
$httpBackend = $injector.get('$httpBackend'); | ||
$resource = $injector.get('$resource'); | ||
$q = $injector.get('$q'); | ||
})); | ||
|
||
|
||
|
@@ -1356,5 +1357,36 @@ describe('resource', function() { | |
); | ||
}); | ||
|
||
it('If timeout promise is resolved, cancel the request', function() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: can you change the test description to match the grammar of other ones in the file? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @caitp done |
||
var canceler = $q.defer(); | ||
|
||
$httpBackend.when('GET', '/CreditCard').respond({data: '123'}); | ||
|
||
var CreditCard = $resource('/CreditCard', {}, { | ||
query: { | ||
method: 'GET', | ||
timeout: canceler.promise | ||
} | ||
}); | ||
|
||
CreditCard.query(); | ||
|
||
canceler.resolve(); | ||
expect(function() { $httpBackend.flush();}).toThrow(new Error("No pending request to flush !")); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If it (flush) uses There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @gkalpak fixed |
||
|
||
canceler = $q.defer(); | ||
CreditCard = $resource('/CreditCard', {}, { | ||
query: { | ||
method: 'GET', | ||
timeout: canceler.promise | ||
} | ||
}); | ||
|
||
CreditCard.query(); | ||
expect(function() { $httpBackend.flush();}).not.toThrow(new Error("No pending request to flush !")); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would leave it at |
||
|
||
|
||
}); | ||
|
||
|
||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if we just made this a switch statement for readability?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@caitp Done