-
Notifications
You must be signed in to change notification settings - Fork 27.4k
fix($resource): Check if timeoutDeferred is null inside $cancelRequest #16037
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 |
---|---|---|
|
@@ -2101,6 +2101,28 @@ describe('cancelling requests', function() { | |
|
||
expect(creditCard.$cancelRequest).toBe(noop); | ||
}); | ||
|
||
it('should not break when calling old `$cancelRequest` after the response arrives', function() { | ||
$httpBackend.whenGET('/CreditCard').respond({}); | ||
|
||
var CreditCard = $resource('/CreditCard', {}, { | ||
get: { | ||
method: 'GET', | ||
cancellable: true | ||
} | ||
}); | ||
|
||
var creditCard = CreditCard.get(); | ||
var cancelRequest = creditCard.$cancelRequest; | ||
|
||
creditCard.$promise.then(function(list) { | ||
cancelRequest(); | ||
}); | ||
|
||
$httpBackend.flush(); | ||
|
||
expect(creditCard.$cancelRequest).not.toThrow(); | ||
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. This wouldn't fail before either. Please change to: expect(cancelRequest).not.toBe(noop);
expect(cancelRequest).not.toThrow(); 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. So, I removed lines 2118 - 2121 and added not.toBe(noop) just above 2124, just like you mentioned in your comments. But now the tests are passing before and after the change I made in resource.js. 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. Have you also changed 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. That's exactly what I missed, thanks 👍🏼 |
||
}); | ||
}); | ||
|
||
describe('configuring `cancellable` on the provider', function() { | ||
|
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 is this for?
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.
This was the piece of code mentioned in the Issue #16016 in the codepen to reproduce this issue. I suppose this is not needed since we'll be calling our function using the expect function?
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.
If you call
cancelRequest
after flushing (as suggested in https://github.com/angular/angular.js/pull/16037/files#r127979323), then this shouldn't be needed (unless I am missing something).