fauxnix

0.0.2 • Public • Published

Fauxnix

NOTE: Fauxnix is a new project and is likely to change.

Fauxnix is a mock websocket connection for receiving and responding to Phoenix channel messages and is heavily inspired by Pretender.

Usage

Fauxnix allows you to create a fake websocket connection and replace the returned object of new WebSocket() calls with the socket you passed in.

const socket = new Fauxnix(function() {
  this.receive("topic", "event", function(payload) {
    return { status: "ok", response: { id: payload.id } };
  });
});

Fauxnix.inject(socket);

Whenever socket receives a message from phoenix.js with a topic of "topic" and an event of "event" Fauxnix will send a reply with the given status and response in the return statement. The payload from a message is passed in as the first argument to this.receives callback.

The call to Fauxnix.inject replaces the returned object of all new WebSocket() calls with the socket we defined.

The topic and event arguments also accept regular expressions.

Contributing

See the CONTRIBUTING document. Thank you, contributors!

License

Fauxnix is Copyright © 2015 thoughtbot. It is free software, and may be redistributed under the terms specified in the LICENSE file.

About thoughtbot

thoughtbot

Fauxnix is maintained and funded by thoughtbot, inc. The names and logos for thoughtbot are trademarks of thoughtbot, inc.

We love open source software! See our other projects or hire us to design, develop, and grow your product.

Package Sidebar

Install

npm i fauxnix

Weekly Downloads

1

Version

0.0.2

License

MIT

Last publish

Collaborators