webmocket

1.0.1 • Public • Published

Build Status

WebMocket

A WebSocket mock, that makes unit testing possible when there is a WebSocket connection involved. It is advisable to check out mock-socket that does the same thing and a bit more. However, at the time of this writing, it had problems working in Firefox.

Installation

npm install webmocket

Usage

let wm = require('webmocket'),
    WebMocket = wm.WebMocket,
    MocketServer = wm.MocketServer;
    
window.WebSocket = WebMocket;
let socket = new WebSocket('test-url'),
    server = new MocketServer('test-url');

socket.addEventListener('message', function...);
socket.onmessage = function...

server.send([1, 2, 3, 4]);
// when finished
server.close();

Important: if you are counting on the socket.onopen event firing, send data using a setTimeout. This is because the open event fires using a timeout after the socket instance has been created.

setTimeout(function() {
    server.send(...);
}, 0);

Readme

Keywords

Package Sidebar

Install

npm i webmocket

Weekly Downloads

0

Version

1.0.1

License

MIT

Last publish

Collaborators

  • nomve