angular-ws-mock
v1.1.1
Published
Mock for AngularJS WebSocket service.
Downloads
9
Readme
angular-ws-mock
Mock for AngularJS WebSocket service.
Install
bower install angular-ws-mock
Usage
describe('My service', function () {
var ws, myService;
beforeEach(module('app', 'wsMock'));
beforeEach(inject(function ($injector) {
ws = $injector.get('ws');
myService = $injector.get('myService');
}));
it('should connect to the WebSocket', function () {
ws.emit('open');
expect(ws.getReadyState()).to.equal(1);
});
ws.emit(event, data)
Emit a new event.
ws.emit('message', {data: 'my message'});
ws.messages
Read the messages sent.
ws.send('hello')
console.log(ws.messages); // ['hello']
ws.reset()
Empty messages.
ws.send('hello')
console.log(ws.messages); // ['hello']
ws.reset();
console.log(ws.messages); // []
License
MIT