Skip to main content

Function: getWebSocketShim()

getWebSocketShim(fetchFn?, factoryInit?): (url, protocols?) => WebSocket

Defined in: testing/src/websocket-shim.ts:35

Creates a WebSocket shim class for use in Cloudflare Workers test environments.

Returns a browser-compatible WebSocket constructor that uses a provided fetch function to initiate WebSocket connections, enabling testing without a separate server.

Parameters​

fetchFn?​

{(input, init?): Promise<Response>; (input, init?): Promise<Response>; (input, init?): Promise<Response>; }

The fetch function to use for WebSocket upgrade requests. Defaults to globalThis.fetch. In test environments, pass SELF.fetch.bind(SELF).

factoryInit?​

WebSocketShimOptions

Optional configuration for headers and queue limits.

Returns​

A WebSocket-compatible constructor class.

new getWebSocketShim(url, protocols?): WebSocket

Parameters​

url​

string | URL

protocols?​

string | string[]

Returns​

WebSocket