Lesson
Override WebSocket Event Handling in Tests with MSW
Override WebSocket event handling on a per-test basis in Vitest using Mock Service Worker.
- Access
- Included
- Transcript
- Needs source
In tests, mocking gives us a way to reproduce different network-related scenarios. Like in this lesson, we will create a runtime event handler for our WebSocket client messages to test a scenario when another user responds to a sent message in the chat.