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

Sort MSW handlers by default #606

Closed
la55u opened this issue Oct 3, 2022 · 1 comment
Closed

Sort MSW handlers by default #606

la55u opened this issue Oct 3, 2022 · 1 comment
Labels
enhancement New feature or request

Comments

@la55u
Copy link

la55u commented Oct 3, 2022

What are the steps to reproduce this issue?

This is a rather unfortunate behavior of MSW: mswjs/msw#814

When there are two handlers specified like this:

rest.get(`${API_URL}/blog-categories/:id`, resolver) // first one with path parameter
rest.get(`${API_URL}/blog-categories/count`, resolver) // second one with static path

Then a request to /blog-categories/count will return the response defined in /blog-categories/:id because that one is matched first.
Since orval generates the mock definitions in an order that is incompatible with the "desired" behaviour, the mock will always return the wrong response.

What were you expecting to happen?

I expect it to resolve the correct mock handler.
A quick fix to this problem could be to sort the mock definitions:
Any handler that has path parameter should be after all the handlers with static paths. This way the above scenario would never apply.

Thank you!

What versions are you using?

Package Version: 6.10.2

@anymaniax anymaniax added the enhancement New feature or request label Jan 6, 2023
@melloware
Copy link
Collaborator

@Will-Mann-16 fixed this in 6.20.0 which upgrades to MSW 2.0 which looks like it contains that MSW fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants