A Cypress plugin to mock WebSocket connections using a cy.intercept-style API. Current stable version is 2.0.0. It allows defining request/response pairs that the app receives during Cypress tests, supports partial matching via ts-pattern, and works with rxjs WebSocket and Apollo GraphQL subscriptions. Key differentiators: runs on top of Cypress's built-in WebSocket communication (no separate mock server needed), supports both a custom constructor and native WebSocket API, and provides static response registration as well as dynamic request handlers.
npm install cypress-mock-websocket-pluginNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Creates a mocked WebSocket endpoint, registers a request/response pair, visits the app, and asserts the response appears in the DOM.
Use { connectionResponseMessage: initialResponse } in options instead of passing as second argument.Set { useNative: true } to mock the native WebSocket API explicitly.Move to options object: { connectionResponseMessage: initialResponse }Ensure request objects have similar shape; use a handler function for custom matching.
Move cy.mockWebSocket() before cy.visit() in your test.
Always chain: cy.mockWebSocket(url).registerSocketRequestResponse(...)
Use a handler function for dynamic matching: .registerSocketRequestResponse(req => {...})