-
Notifications
You must be signed in to change notification settings - Fork 170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add filterCalls(), testCalls() #83
Conversation
URL matcher compilation was refactored so it could be shared between `compileRoute` and the new methods. Documentation and tests included.
Nice idea, thanks for submitting One edge cases possibly not covered (don't have time to review the code properly this second) is what about if two matchers match a given url. fetch mock will respond to the first one matched, but what if in your test you check callsMatching for the second one. Could lead to hard to trace mistakes in the tests.
That's weird - it's supposed to (unless I changed the behaviour sometime and can't remember the details any more). Aside from getting around this bug/unhelpful behaviour, do you see any other advantages with your approach? Any use cases in mind? I don't particularly like the way it is now either - was a bit of a compromise for v2/3 to avoid requiring users to name every route. I think it needs some careful thought though before changing the way it works again. |
I've written a test to cover the |
1 similar comment
I've written a test to cover the |
Let me be clearer about where my expectations conflicted with the actual API. First, in code: fetchMock.mock('^http://example.com/');
fetch('http://example.com/one/two').then(() => {
fetchMock.called('^http://example.com/'); // true
fetchMock.called('^http://example.com/one'); // false (surprising to me)
fetchMock.called(/one\/two$/); // false (surprising to me)
fetchMock.calledMatching('^http://example.com/'); // true
fetchMock.calledMatching('^http://example.com/one'); // true
fetchMock.calledMatching(/\/one\/two$/); // true
}); As you see, I thought that I could meaningfully pass arbitrary I think the docs contributed to that misunderstanding, as the argument name And, come to think about it - Is it ever useful to pass an unknown route into |
I'm afraid I don't fully understand what you mean here. Do you mean something like this? fetchMock.mock('^http://hey')
.mock('http://hey.there');
fetch('http://hey.there') // or anything that would match a route (or routes)
.then(() => {
fetchMock.calledMatching(/hey/); // true
fetchMock.callsMatching(/hey/); // {routed: [['http://hey.there', opts]], unrouted: []}
}); |
The thing is, |
…o call-matching # Conflicts: # test/spec.js
Here is the case I'm concerned about
Here's where I stand on this at the moment
Given those points, I think updating the docs and opening an issue with a title like 'Behaviour of called(matcher) is confusing', referencing this PR, would be a good way to see if there is demand for a change in behaviour. |
Thanks for raising those issues |
This combines a proposed implementation of #88 with a doc fix for #87 which originally prompted me to come up with this API. URL matcher compilation was refactored so it could be shared between
compileRoute
and the new methods.Notes:
callsMatched()
andcalledMatched()
, but in light of @wheresrhys's concerns, I now think it would be better to distance them fromcalls()
andcalled()
to reduce confusion, hence their new names.normalizeRequest
into the handling of matchers, in the new methods only (seecompileUserUrlMatcher
). This may or may not be desired but was the quickest way to get roughly what I wanted here.EDIT: I've rewritten most of this description for clarity. Further discussion of the separate motivations for this PR probably belongs separately in issues #87 and #88.