-
Notifications
You must be signed in to change notification settings - Fork 27.4k
feat(ngMock): add flushByIndex function #6412
Conversation
Thanks for the PR! Please check the items below to help us merge this faster. See the contributing docs for more information.
If you need to make changes to your pull request, you can update the commit with Thanks again for your help! |
Adds a flushByIndex function to allow pending requests on httpBackend to be flushed in an arbitrary order.
Updated with the issue template |
@atogata currently the TravisCI build is failing (https://travis-ci.org/angular/angular.js/jobs/19426249) so this PR needs more work. But besides the build issues I would love to know more about your actual use-case. If I'm not mistaken request are flushed in the order of expectations set so you can control the order by registering expectations. Could you provide an example unit test that is easier to write with the index-based flushing? |
@pkozlowski-opensource Thank you for your response, the exact use case depends highly on some specifics of the system I’m working with, but I will try to explain as clearly as possible. We have a system that can be called in a manner like: The /events endpoint will always return the result of /events/eventKeyA, along with other entities. Since both endpoints can be slow, we have some logic in place such that service.get(‘/events/eventKeyA’) can return data as soon as it’s available from the /events call and not have to wait for the singular call. The problem in testing this seems to be that httpBackend.expectGET(‘/v1.0/events’); will cause /events to be flushed first, even though this particular test needs /events/eventKeyA to be flushed first. httpBackend.expectGET(‘/v1.0/events/eventKeyA’); The alternative above seems to cause the test to throw an error, As for the failing Travis CI build, I did push up a new commit with the corresponding build https://travis-ci.org/angular/angular.js/builds/19426708, however it seems like 9039.2 hung. Would you be able to restart it? |
Also, included below is the actual test using this function.
|
I'm sorry, but I wasn't able to verify your Contributor License Agreement (CLA) signature. CLA signature is required for any code contributions to AngularJS. Please sign our CLA and ensure that the CLA signature email address and the email address in this PR's commits match. If you signed the CLA as a corporation, please let us know the company's name. Thanks a bunch! PS: If you signed the CLA in the past then most likely the email addresses don't match. Please sign the CLA again or update the email address in the commit of this PR. |
@mary-poppins I've signed the CLA again under the correct e-mail. @pkozlowski-opensource CI build passed (https://travis-ci.org/angular/angular.js/builds/21078576), are there any updates on the status of this PR? Thank you for your time! |
CLA signature verified! Thank you! Someone from the team will now triage your PR and it will be processed based on the determined priority (doc updates and fixes with tests are prioritized over other changes). |
02dc2aa
to
fd2d6c0
Compare
cad9560
to
f294244
Compare
e8dc429
to
e83fab9
Compare
4dd5a20
to
998c61c
Compare
Superseded by #14967 |
Request Type: feature
How to reproduce:
Component(s): ngMock
Impact: small
Complexity: small
This issue is related to:
Detailed Description:
I've recently needed to flush httpBackend requests in an arbitrary order to add unit tests around an edge case. This PR satisfies that need.
Other Comments:
Adds a flushByIndex function to allow pending requests on httpBackend to be flushed in an arbitrary
order.