Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timeout error running simple test in jest #167

Open
ravi-2912 opened this issue Dec 16, 2023 · 3 comments
Open

Timeout error running simple test in jest #167

ravi-2912 opened this issue Dec 16, 2023 · 3 comments

Comments

@ravi-2912
Copy link

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.

@EsmaNErdem
Copy link

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?

@Sheldenshi
Copy link

Having the same issue

@Sheldenshi
Copy link

You need to import WebSocket from 'mock-socket'

import { WebSocket } from 'mock-socket';

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants