jest-websocket-mock
jest-websocket-mock copied to clipboard
Timeout error running simple test in jest
I am running the following test in NodeJS.
import WS from 'jest-websocket-mock';
import WebSocket from 'ws';
test('example test with jest-websocket-mock', async () => {
const server = new WS('ws://localhost:1234');
const client = new WebSocket('ws://localhost:1234');
await server.connected;
client.send('hello');
await expect(server).toReceiveMessage('hello');
expect(server).toHaveReceivedMessages(['hello']);
}, 25000);
And I get the following error
Please could you suggest how can I resolve this.
I have the same issue where I am trying mock server side websocket to test React client side connection. Were you able to solve this?
Having the same issue
You need to import WebSocket from 'mock-socket'
import { WebSocket } from 'mock-socket';