Replies: 1 comment 1 reply
-
I've been trying to create a utility function similar to how I do it with msw's setup server: export function startMockServer(handlers: HttpHandler[]) {
const server = setupServer(...handlers)
beforeAll(() => server.listen({ onUnhandledRequest: 'error' }))
afterEach(() => server.resetHandlers())
afterAll(() => server.close())
return server
} But it seems that it is not working for msw's browser worker. What worked for me is this: // browser.ts
import { setupWorker } from 'msw/browser'
export const worker = setupWorker() Then on your test file: import { worker } from '../../mocks/browser'
import { handlers } from '../../mocks/handlers'
describe('test', async () => {
await worker.start()
worker.use(...handlers)
test(...)
}) |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I use
msw/browser
to setup worker, but when i awaitworker.start
, it stuckBeta Was this translation helpful? Give feedback.
All reactions