title: Unit testing of websocket application by sinon.js
body: <p>I have tried to do unit testing for a web socket application using sinon.js, </p>
  
  <p>One of the users on github of <a href="https://github.com/cjohansen/Sinon.JS/issues/174"><strong>sinon</strong></a>, did this, but I am not able to understand how it does help to unit test websocket applications for validating the received data which was sent to fake server.</p>
  
  <pre><code>var dummySocket = { send : sinon.spy()};
  sinon.stub(window, 'WebSocket').returns(dummySocket);
  dummySocket = new WebSocket('ws://html5rocks.websocket.org/echo');
  dummySocket.onopen();
  dummySocket.onmessage(JSON.stringify({ hello : 'from server' }));
  // You can assert whether your code sent something to the server like this:
  sinon.assert.calledWith(dummySocket.send, '{"the client":"says hi"}');
  </code></pre>
  
  <p><strong>My questions are</strong> </p>
  
  <ul>
  <li>How can I receive the same data from fake server which have been sent to server earlier.</li>
  <li>How can I send data to fake server by using <code>send</code> method of fake socket object(eg:- <code>socket.send()</code>)?</li>
  <li>How can I get data from server on <code>dummySocket.onmessage = function (msg){}</code></li>
  </ul>
  
  <p>With <strong>sinon.js</strong>, I could not get the any process to  create fake <strong>websocket</strong> object like for fake <code>XMLHttpRequest</code> and <code>server</code> by using respectively <code>useFakeXMLHttpRequest()</code> and <code>fakeServer.create()</code></p>
  
  <p><strong>Is there any process to achieve this on sinon.js?</strong></p>