As a websockets client developer
I want to mock the WebSocket object
So I can simulate interaction with a websockets server on the browser
And inspect a log of sent and received messages
And test my client code without the need to setup an actual WebSockets server.
Sockete.Server.configure('ws://fake.host', function () {
this.onmessage('blah').respond('Ok buddy!');
this.onmessage('Wrong message').fail('So sorry');
// this.onconnect().fail('Nope!')
});
// Replace native window.WebSocket with Sockete.Client
Sockete.mock();
var socket = new WebSocket('ws://fake.host');
socket.readyState // => 1 (CONNECTED)
socket.onmessage = function (evt) {
console.log(evt.data)
}
socket.send('blah'); // => logs 'Ok buddy!'
socket.send('Wrong message'); // => closes connection and fires socket.onclose()
git pull
bundle install
ruby test/app.rb
open test/index.html
Change version in ./Jfile and build distribution with
jbundle
Commit and push.
- Be able to inspect message history on both server and client (kinda the point of this library)
- Tokenized server URLs and messages, so we can test query variable strings, etc.
- Be able to facading native Websocket (instead of completely replacing) so we can use with real server while maintaining history and testing capabilities (cool fo running integration tests?)