Course lesson
Test WebSockets in Vitest with MSW
Let's write an integration test for our <Chat/> component in Vitest and React Testing Library.
- Duration
- 6 min
- Access
- Free
- Transcript
- Needs source
Let's write an integration test for our <Chat/> component in Vitest and React Testing Library.
The WebSocket interception in MSW requires a global WebSocket class. You are covered if you're using Node.js v22 or higher since that global class exists there. But for older versions, we will create a custom Vitest environment to polyfill it using undici.