socks-io
Your socks for the socket-io. Just a very simple non-blocking mocking lib, but useful if you don't care about the server and just want to test the clients interactions. Supports socket.on
, socket.emit
and socket.open
.
Contents
Installation
yarn add socks-io
or
npm i socks-io
Usage
In this example Session
is a class responsible for handling a client interactions we want to test. Let's add two clients to the server and let them interact with each other. To do so, we just need to mock the implementation of the socket-io connect
function, attach our clients and just run the tests. More below :)
;;; let COUNT = 0;const SServer = ; //global server instance // mock the connect(endpoint, socketConfig)jest; ;
Notes
Emit socket.emit('/join', 'room)
to join a room, and SServer.rooms
to check who's inside.