Skip to content

Handlers or SetupServer() #1003

Answered by kettanaito
charlestbell asked this question in Q&A
Discussion options

You must be logged in to vote

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 and setupWorker 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 …

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by charlestbell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants