Skip to content

test failed with msw, but works with other mock server library #915

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

You must be logged in to vote

Hey, @tofutree23.

There are a few issues with your setup that may be causing the behavior you're experiencing.

  1. Two beforeAll hooks, where first enables the mocking and the second disables it immediately. I believe you meant to use afterAll:
beforeAll(() => server.listen({ onUnhandledRequest: 'warn' }))
beforeEach(() => server.resetHandlers())
-beforeAll(() => server.close())
+afterAll(() => server.close())
  1. If you configure Axios with any options that affect request URL (i.e. base URL), make sure you account for those options when declaring handlers. For instance, in the case of base URL, export that URL and prepend it to each handler:
import { BASE_URL } from './my-axios-setup'

const s…

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@tofutree23
Comment options

@kettanaito
Comment options

@tofutree23
Comment options

@kettanaito
Comment options

@tofutree23
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
bug Something isn't working scope:node Related to MSW running in Node
2 participants
Converted from issue

This discussion was converted from issue #914 on September 15, 2021 08:28.