-
Notifications
You must be signed in to change notification settings - Fork 27.4k
feat(ngMock, ngMockE2E): add option to match latest definition for $h… #16560
Conversation
…ttpBackend request Closes angular#16251 Closes angular#11637
f3fa83b
to
35aaef3
Compare
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.
LGTM except for the lack of docs 📖
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.
Looks good but needs docs and perhaps another test?
while ((definition = definitions[++i])) { | ||
var i = matchLatestDefinition ? definitions.length : -1, definition; | ||
|
||
while ((definition = definitions[matchLatestDefinition ? --i : ++i])) { |
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 is dangerous stuff due to the subtle difference between prefix and postfix operators. But given that we were doing this already I guess it'll be fine.
src/ngMock/angular-mocks.js
Outdated
@@ -1507,6 +1509,15 @@ function createHttpBackendMock($rootScope, $timeout, $delegate, $browser) { | |||
return chain; | |||
}; | |||
|
|||
$httpBackend.matchLatestDefinition = function(value) { | |||
|
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.
is this blank line needed / in keeping with the rest of the code?
src/ngMock/angular-mocks.js
Outdated
$httpBackend.matchLatestDefinition = function(value) { | ||
|
||
if (isDefined(value)) { | ||
matchLatestDefinition = value; |
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.
don't we normally return this
when it is a setter to allow chaining?
test/ngMock/angular-mocksSpec.js
Outdated
hb.flush(); | ||
expect(callback).toHaveBeenCalledOnce(); | ||
} | ||
); |
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.
Do we already have tests for the order when this is false?
test/ngMock/angular-mocksSpec.js
Outdated
hb('GET', '/url1', null, callback); | ||
expect(callback).not.toHaveBeenCalled(); | ||
hb.flush(); | ||
expect(callback).toHaveBeenCalledOnce(); |
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.
Should we check that it continues to work backwards if the last one doesn't match?
src/ngMock/angular-mocks.js
Outdated
@@ -1507,6 +1509,15 @@ function createHttpBackendMock($rootScope, $timeout, $delegate, $browser) { | |||
return chain; | |||
}; | |||
|
|||
$httpBackend.matchLatestDefinition = function(value) { |
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.
I think we needed docs here.
… for $httpBackend request
235d954
to
ed92fb2
Compare
…ttpBackend request
Closes #16251
Closes #11637
What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
Feature
What is the current behavior? (You can also link to an open issue here)
See #11637
What is the new behavior (if this is a feature change)?
Config option to change the behavior
Does this PR introduce a breaking change?
No
Please check if the PR fulfills these requirements
Other information:
First draft to discuss the API.
As noted in #16251, it's not possible (afaics) to put the option on the httpBackendProvider, because they cannot be decorated. It's also not useful to put the method on the ng.httpBackendProvider, because that's not where it's needed. The option to switch it directly from httpBackend could also be used to migrate tests step by step or use it only for new tests. Another option would be a new "$httpBackendMocksProvider" or similar (but I don't think that's very useful).