Skip to content
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 query strings to .pendingMocks() #2234

Open
josh18 opened this issue Oct 20, 2021 · 4 comments
Open

Add query strings to .pendingMocks() #2234

josh18 opened this issue Oct 20, 2021 · 4 comments
Labels
support General questions or support.

Comments

@josh18
Copy link

josh18 commented Oct 20, 2021

Context

Currently it is easy to miss that an interceptor isn't matching due to mismatching query strings.

Alternatives

This may be a breaking change if users are expecting specific messages so may not be ideal. An alternative would be to expose a new function such as pendingInterceptors() which would contain a lot more information that could be useful.

Has the feature been requested before?

I couldn't find any but there is another user who was confused by this: #2182

If the feature request is accepted, would you be willing to submit a PR?

Yes

@gr2m
Copy link
Member

gr2m commented Nov 8, 2021

@mastermatt you wrote

nock.pendingMocks() is not meant to return the search component of the href

I wonder why though? Can you elaborate?

@gr2m gr2m added the support General questions or support. label Nov 8, 2021
@mastermatt
Copy link
Member

I don't know. A lot of nock comes from years of if-y documented incremental changes.
My comment is not a statement that it should behave like it does, just that it's current implementation does do it explicitly.

If I were to guess, I think its design was a judgement call how to represent pending interceptors as strings. One could argue that it should only rerun the host vs more and more eg. path, query, etc.

Personally I've never been a fan of it returning strings. Intuitively, I thought it should return Interceptors directly. 🤷
I only use it in afterEach test hooks. So I just have a little helper fn I use to get what I want.

@gr2m
Copy link
Member

gr2m commented Nov 8, 2021

I only use it in afterEach test hooks

same :)

I'll dig more into nock's code next week, maybe I'll find out why the method behaves the way it currently does

@josh18
Copy link
Author

josh18 commented Nov 8, 2021

So I just have a little helper fn I use to get what I want.

Are you keeping track of the interceptors separately? I don't think there is a way to access all the interceptors using nock is there?

pendingInterceptors() might be the better option to preserve legacy behaviour and enable more flexibility.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
support General questions or support.
Projects
None yet
Development

No branches or pull requests

3 participants