https://github.com/nikorablin/socket.io-stub
Stub for socket.io testing
https://github.com/nikorablin/socket.io-stub
nodejs socket-io socketio testing
Last synced: 3 months ago
JSON representation
Stub for socket.io testing
- Host: GitHub
- URL: https://github.com/nikorablin/socket.io-stub
- Owner: nikorablin
- License: mit
- Created: 2018-03-07T14:52:36.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-03-07T16:23:02.000Z (over 8 years ago)
- Last Synced: 2024-10-09T12:33:55.583Z (over 1 year ago)
- Topics: nodejs, socket-io, socketio, testing
- Language: JavaScript
- Size: 99.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Socket.io Stub
A socket stub to use when testing [socket.io](https://socket.io/) code
### Using the Stub
```js
const manager = socket => {
socket.on('ping', payload => socket.emit('pong', payload));
};
describe('Testing socket', () => {
it('ping will pong', () => {
const socket = new SocketStub();
manager(socket);
socket.simulate('ping', true);
expect(socket.emitted.length).to.equal(1);
expect(socket.emitted).to.eql([['pong', true]]);
});
});
```
### Installation
```
npm i socket.io-stub --save-dev
```
```
yarn add socket.io-stub --dev
```
### Tests
```
yarn test
```
### Methods
**new SocketStub(properties: ?object)**
Instantiate a new socket stub. You can pass a properties object into the constructor to apply properties on the Socket
**simulate(event: string, payload: any)**
Simulate an event on the socket
**clear**
Clear all tracked emitted events from socket