socket.io-mock
A mock to test the socket.io library implementation.
This is an enhanced copy of socket-io-mock.
I made this project becuase socket-io-mock
does not appear to be actively maintained. This project takes advantage of eventemitter
covering more of the socket.io-client library. If you see any bugs or lack of support for socket.io features, please drop an issue.
Installation
npm install socket.io-mock
Usage
Simply create new socket mock with:
import MockedSocket from 'socket.io-mock';
let socket = new MockedSocket();
And use the socket as if it was a normal Socket.io socket.
For example:
import SocketMock from 'socket.io-mock';
import { should } from 'chai';
describe('Fast and isolated socket tests', function(){
it('Sockets should be able to talk to each other without a server', function(done) {
let socket = new SocketMock();
socket.on('message', function (message) {
message.should.be.equal('Hello World!');
});
socket.socketClient.emit('message', 'Hello World!');
});
});