-
Notifications
You must be signed in to change notification settings - Fork 27.5k
ngMock - why does $httpBackend match the first and not the last mock definition? #11637
Comments
I think this sounds like a good idea, but of course it would be quite a breaking change to applications. |
This is actually a really annoying feature when it comes to E2E testing with Protactor, as currently there's no module available that will allow you to keep reference to the promise returned by the mock So essentially, it's impossible to test a success response and then immediately test a failure from the same API endpoint without having to do a full browser refresh to clear down the intercepts. Allowing the option of matching the last added regex instead of the first would make this kind of testing trivial. But essentially for me at the moment, integrating Protractor into my tests is impossible due to the high number of tests that can't be changed easily. |
@petebacondarwin Are there still any chances this could land in 1.5, as there already were 2 beta releases? |
Why don't we just add something like resetDefinitions() along the lines of resetExpectations() ? This will at-least help in setting new definitions. |
You could also add it as an option that would default to the current code, so it would be backwards compatible. It's really just a matter of changing |
Am I reading this correctly - I see
|
I was also thinking of making this configurable. In any case, a PoC PR is very welcome. |
We are happy to merge a PR that implements a non-breaking change form of this feature. It looks like something along the lines of |
Personally, I'd prefer |
This PR adds a new method to $httpBackend that allows to override any existing definition, by adding the new definition at the beginning of the definition list, not at the end of it, like $httpBackend.when does. Closes angular#11637
This PR adds a new method to $httpBackend that allows to override any existing definition, by adding the new definition at the beginning of the definition list, not at the end of it, like $httpBackend.when does. Closes angular#11637
This PR adds a new method to $httpBackend that allows to override any existing definition, by adding the new definition at the beginning of the definition list, not at the end of it, like $httpBackend.when does. Closes angular#11637
…ttpBackend request Closes angular#16251 Closes angular#11637
…ttpBackend request Closes angular#16251 Closes angular#11637
Is there any reason why
$httpBackend
matches the first and not the last mock definition? If it worked the other way around (i.e.$httpBackend.when
added new mock definitions to the beginning ofdefinitions
array instead of the end of it) it would be much easier to overwrite already mocked requests.I've got some default mock definitions common for almost all tests that are loaded before each test and would like to be able to easily overwrite them in some specific tests.
I wanted to prepare PR that changes this, but there's even a unit test that explicitly checks for this behavior.
EDIT: In ngMock module unit tests like
should match headers if specified
orshould match data if specified
, the first mocks are more specific than the later ones. In a real app, I'd expect something opposite - one would create general mocks for most tests and then define more specific ones in selected tests.The text was updated successfully, but these errors were encountered: