-
4ba6b11: # Migrate to MSW 2.x
Mock Service Worker 2 features stream responses, which makes mocking a SignalR hub significantly easier. The mock request handler implementation now uses Server Sent Events instead of Long-Polling.
signalRHandlers
was renamed tosignalRHub
to better reflect the changed role:- import { signalRHandlers } from "msw-signalr"; + import { signalRHub } from "msw-signalr"
signalRHub
returns an object withhandlers
,connections
, andbroadcast
function, which takes the role of the formally globalsend
.- export const server = setupServer(...signalRhandlers("/hub")); + export const hub = signalRHub("/hub"); + export const worker = setupWorker(...hub.handlers);
- send("foo", "bar") + hub.broadcast("foo", "bar")
The
connections
property can now be used to send messages to individual clients:hub.connections.get("some-id").send("foo", "bar");