Handlers or SetupServer() #1003
-
Which one should I use? Handlers or SetupWorker()? It is not clear in the docs. The docs mention both Handlers I'm building a react-native app. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hi, @charlestbell. Sorry about the confusion. Handlers (or "request handlers") are functions that describe what requests to capture and how to mock their responses. Think of it as a network behavior description. Handlers do not do any interception/mocking on their own, they are but a set of instructions on what to do when a matching request happens. APIs like As you're building a React Native application, you'll be using |
Beta Was this translation helpful? Give feedback.
Hi, @charlestbell. Sorry about the confusion.
Handlers (or "request handlers") are functions that describe what requests to capture and how to mock their responses. Think of it as a network behavior description. Handlers do not do any interception/mocking on their own, they are but a set of instructions on what to do when a matching request happens.
APIs like
setupServer
andsetupWorker
enable interception of requests. Calling them is what makes MSW aware of the requests that happen in your application. As you've seen from the Getting started tutorial, you provide request handlers to one of those APIs (or both!) depending on the environment you wish to enable mocks in.As you're building …