jest-websocket-mock

JSON →
library 2.5.0 ·javascript
verified Jun 7, 2026

A library for mocking WebSocket servers in Jest tests. Version 2.5.0 is the current stable release with no fixed cadence. It provides a WS class to simulate a WebSocket server, track messages, and assert interactions. Supports JSON protocol auto-serialization, error simulation, and graceful close. Ships TypeScript definitions. Key differentiators: built-in connected/closed/nextMessage promises for async test flow, static clean() method to reset between tests, and compatibility with popular patterns like redux-saga and react hooks via example code.