тестирование websocket с шуткой - PullRequest
0 голосов
/ 27 апреля 2020

Я пытаюсь написать тест для этой веб-розетки и всегда получаю эту ошибку:

  #clients › it should create a room of clients on connection
  Unhandled error. (Error: Unexpected server response: 400

  at ClientRequest.<anonymous> (node_modules/ws/lib/websocket.js:580:7)
  at TCP.onStreamRead (internal/stream_base_commons.js:182:23))Error [ERR_UNHANDLED_ERROR]: Unhandled error. (Error: Unexpected server response: 400
  at ClientRequest.<anonymous> (node_modules/ws/lib/websocket.js:580:7)
  at TCP.onStreamRead (internal/stream_base_commons.js:182:23))
  at abortHandshake (node_modules/ws/lib/websocket.js:698:15)
  at ClientRequest.<anonymous> (node_modules/ws/lib/websocket.js:580:7)

это мой код, я новичок в тестировании в целом, может кто-нибудь объяснить мне, как издеваться этот звонок? При подключении я хотел бы иметь возможность получить путь сокета для создания идентификатора

it('it should create a room of clients on connection', (done) => {
    let rooms = new Map();
    const wss = new WebSocket.Server({ port: 0, path: '/12345?isDoctor=true' }, () => {
        const ws = new WebSocket(`ws://localhost:${wss.address().port}`);
        expect(rooms.size).toEqual(0)
    });

    wss.on('connection', (ws, req) => {
        console.log(req.url, 'url'); // I never get this log
        const path = req.url.slice(1);
        const indexOfParams = path.indexOf('?');
        const id = path.slice(0, indexOfParams);

        if ( rooms.has(id) === false) {
            rooms.set(id, [ws]);
        }
        expect(rooms.size).toEqual(1);
        wss.close(done);
    });
});
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...