angular-ws-mock

1.1.1 • Public • Published

angular-ws-mock

Build Status Dependency Status devDependency Status

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

Dependencies (0)

    Dev Dependencies (6)

    Package Sidebar

    Install

    npm i angular-ws-mock

    Weekly Downloads

    2

    Version

    1.1.1

    License

    MIT

    Last publish

    Collaborators

    • neoziro