Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/thoov/mock-socks
Browse files Browse the repository at this point in the history
  • Loading branch information
thoov committed Dec 29, 2014
2 parents 1b9e4f1 + c6ffacd commit 6a67248
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ mockServer.on('connection', function(server) {

**NOTE:** This should look very familiar if you are using a node framework such as [ws](https://github.com/einaros/ws).

### MockSockets
### MockSocket

MockSocket is a drop in replacement for the standard [WebSockets global](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket)
found in all browsers. The goal is to be able to do the following and not notice anything different:
Expand All @@ -59,7 +59,8 @@ window.WebSockets = MockSocket;
var mockSocket = new WebSocket('ws://localhost:8080');

mockSocket.onopen = function(e) {
this.send('some data'); // this will trigger the mock server's on message callback
// this will trigger the mock server's on message callback
this.send('some data');
};
mockSocket.onmessage = function(e) {
var data = e.data; // the message is stored in the event's data property
Expand All @@ -76,13 +77,14 @@ Here is an example of how to start using mock-sockets inside of your test suite
a qunit test but this could easily be incorporated into most suites:

```js
// Set the global WebSocket object to our MockSocket object. This allows us to do: new WebSocket and
// create a MockSocket object instead of a native WebSocket object.
// Set the global WebSocket object to our MockSocket object. This allows us to
// do: new WebSocket and create a MockSocket object instead of a native WebSocket object.
window.WebSocket = MockSocket;

module('Simple Test',
setup: function() {
// NOTE: you must create a new MockServer before you create a new MockSocket object. It is a good idea to place this
// NOTE: you must create a new MockServer before you create
// a new MockSocket object. It is a good idea to place this
// logic either at the top of your test or in a setup function.
var mockServer = new MockServer('ws://localhost:8080');
mockServer.on('connection', function(server) {
Expand Down Expand Up @@ -118,8 +120,8 @@ asyncTest('basic test', function(){
```js
require('./path/to/mocksocket/src/main');

// Here the objects have been set to the global object and can be referenced by: MockServer and MockSocket

// Here the objects have been set to the global
// object and can be referenced by: MockServer and MockSocket
```

## Building from source / Running tests
Expand All @@ -134,10 +136,10 @@ require('./path/to/mocksocket/src/main');
**NOTE:** If you make any changes to the src files you will need to run gulp to generate the new
dist files

### Feedback or issues
### Feedback / Issues

If you have any feedback, encounter any bugs, or just have a question, please feel free to create a [github issue](https://github.com/thoov/mock-socket/issues/new) or send me a tweet at [@thoov](https://twitter.com/thoov).

## FAQ
### FAQ

* **LICENSE**: This library falls under the [MIT license](https://github.com/thoov/mock-socket/blob/master/LICENSE.txt)

0 comments on commit 6a67248

Please sign in to comment.