Feature toggle request: Drop unhandled network requests instead of bypassing them #1665
Replies: 3 comments 2 replies
-
Hi, @amir-ziaei. Thanks for the proposal! Can you please tell me more about what you mean by "drop any network requests"? We do have something that sounds very similar to your proposal, that being the server.listen({ onUnhandledRequest: 'error' }) This will throw an exception whenever a request happens that doesn't have a corresponding request handler. Would this address your concern? |
Beta Was this translation helpful? Give feedback.
-
Generally speaking, my opinion on the deterministic handling of requests is that there must only be one place where you/the library can affect the request resolution: that's request handlers. So unless you have a request handler that explicitly says "whenever X request happens abort it" (which we do support), MSW must not affect the request resolution in any way. This kind of restricted responsibility makes it easy to reason about request behavior and observe what handlers you have at any given point of time that may affect it. Even the I don't think there's any intention to change this approach but there's a few things around it that can contribute to a better DX, such as #951. |
Beta Was this translation helpful? Give feedback.
-
This is a problem for my project as well. I have an API a bit like graphql, where all requests are posts to the same endpoint, and the body determines the result type. I have a wrapper function that uses the |
Beta Was this translation helpful? Give feedback.
-
Scope
Adds a new behavior
Compatibility
Feature description
I am delighted with how the msw library warns me about unhandled network requests, as shown in the example below:
However, I would like to propose an additional opt-in feature: I suggest the option to automatically drop any network requests that do not have a matching handler by default. By enabling this feature, devs will be required to provide a handler for all requests, resulting in more deterministic tests.
I would love to hear your opinions and thoughts on this.
Beta Was this translation helpful? Give feedback.
All reactions