-
Notifications
You must be signed in to change notification settings - Fork 158
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
Made pretender._handlerFor public #307
base: master
Are you sure you want to change the base?
Conversation
47364fc
to
2fc1259
Compare
Hi @xg-wang , we need this functionality in a large codebase for various use-cases, so mirage can also make it public afterwards, let me know if you have further questions. Otherwise we would like this to be merged. |
Hi @izelnakri, in your example,
Is the need here about not able to access the originally defined handler therefore you need to read it from within your test? |
yes 🤦 its is |
Interesting, the calls return the handler? I'll try this out and get back to you! Thank you very much for your response/showing me the alternatives! Might be useful to document this in the README.md |
@izelnakri no problem! Let me know if that works for you. I can update the README later |
ok I just found one more issue with your proposed solutions: 1- This is interesting for few test cases I will try. Would be also nice to document it. 2- In a big application with many route handlers your second solution would mean exporting the route handler as ES module function export, currently routes can be registered without separating the handler, and its more readable this way. We already kind of put a symbolic reference by calling the http method and declaring a route string:
|
Hi @xg-wang , I hope the arguments I made above are convincing for this pull request to be merged, as it is just a removal of the There was a reason why this method was needed internally in the library in the first place, and very good reasons to be made public. |
@izelnakri I think we need
I'm also not sure what is a public way to re-register a route handler for Sorry I do not currently have time for my own thoughts here, but wanted to share with you what I think is needed to make the API public. To unblock yourself from the objections it looks like you can do it with public APIs
|
Awesome, Ill read the points in detail. Thank you for your detailed answer, and looking into this in depth 👍 |
Reasoning:
Many complex test suites use this library to mock their backend server, and these tests and route handlers can get very complex. When we write e2e tests it is useful to override route handlers make server respond with error. However in such scenarios it would be also useful to test that user can fix their errors when server goes online/behaves correctly while staying on the same page with the error. Thus a developer would like to override the overridden route with historical route handling logic, instead of overriding with custom logic twice:
This change encourages developers to use this pattern, which makes tests behave slightly more like their backend, if their backend is mocked correctly, and makes the test easier to debug since there are less versions of mocking of the same endpoint in the entire test suite.
Additional details:
yarn install
for contributing.