jest-websocket-mock icon indicating copy to clipboard operation
jest-websocket-mock copied to clipboard

Timeout error running simple test in jest

Open ravi-2912 opened this issue 1 year ago • 3 comments

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

image

Please could you suggest how can I resolve this.

ravi-2912 avatar Dec 16 '23 00:12 ravi-2912

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?

EsmaNErdem avatar Feb 08 '24 03:02 EsmaNErdem

Having the same issue

Sheldenshi avatar May 01 '24 23:05 Sheldenshi

You need to import WebSocket from 'mock-socket'

import { WebSocket } from 'mock-socket';

Sheldenshi avatar May 01 '24 23:05 Sheldenshi