A tool to test socket io servers more easily without dealing with callbacks
npm install socket.io-await-testTesting a socket io server does need to be hard. Rather than registering handlers for messages, this library allows you to wait for the server to send you the response you expect using the await keyword in an async test function.
``js
const tester = new SocketTester(client);
const pongs = tester.on('pong');
client.emit('ping', 1);
client.emit('ping', 2);
await pongs.waitForEvents(2)
assert.equal(pongs.get(0), 2)
assert.equal(pongs.get(1), 3)
`
`sh`
npm install --save-dev socket.io-await-test
Import in your test
`js`
const { SocketTester } = require('socket.io-await-test')
``
const tester = new SocketTester(client);
#### on
Get an instance of a SocketSubscription which collects all messages received for the given event name.
```
const pongs = tester.on
#### waitForEvents(num: number): Promise
Returns a promise that will be resolved when a the specified number of events have been triggerd on the socket subscription.
#### waitUntil(predicate: (value: T) => boolean): Promise
Returns a promise that will be resolved when the given predicate returns true for a received message.
#### waitForAny(): Promise
Returns a promise that will be resolved whenever a message is received.