Skip to content

Allow override same endpoint on setup #1410

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

You must be logged in to vote

Hey, @SevenOutman. Thanks for raising this.

I think your abstracting things a little but too high the chain. Instead of wrapping the entire setupServer call, abstract the handlers.

export const defaultUserHandlers = [
  rest.get('/api/current-user', resolver),
  // ...as many as you need to describe a happy path.
]

Then, in tests just provide this handlers list to the setupServer call:

import { setupServer } from 'msw/node'
import { defaultUserHandlers } from './handlers/user'

const server = setupServer(...defaultUserHandlers)

This should cover the repetition for the test cases that rely on the happy path handlers defined in defaultUserHandlers.

Now, when it comes to overrides, you can p…

Replies: 1 comment 6 replies

Comment options

You must be logged in to vote
6 replies
@kettanaito
Comment options

@SevenOutman
Comment options

@kettanaito
Comment options

@SevenOutman
Comment options

@kettanaito
Comment options

Answer selected by kettanaito
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