Simulate socket connections
Intercepts socket.io connection and allows to simulate socket.io server behaviour.
Full documentation is available here: http://canjs.github.io/canjs/doc/can-fixture-socket.html.
can-fixture-socket module exports an object with:
With three simple steps you can test your real-time application that uses socket.io:
Use npm to install can-fixture-socket:
npm install can-fixture-socket --save
Lets say we wanted to test a simple app that connects to
once connected, creates a message, and logs when the message is created.
That app could look like the following:
var socket = ;socket;socket;
To test this, we'll first use can-fixture-socket.Server to intercept the socket connection:
var io = ;var fixtureSocket = ;var mockServer = io;
Now we can mock the socket server by creating socket event listeners and emitting socket events:
We also can use socket.io acknowledgement callbacks:
var socket = ;socket;
With can-fixture can-fixture.store we can create a store of items and emulate a fully working CRUD service. Optionally, we can use can-set.Algebra to power our store filtering, pagination, and sorting abilities.
// Import can-fixture that provides `store` method for creating a store:var fixture = ;var canSet = ;// Create a fixture store:var messagesStore = fixture;
We can mock the socket.io connection with the rich behavior of fixture stores using the requestHandlerToListener helper. The
converts a fixture store request handler (e.g. getListData) to a socket.io event listener.
var fixtureSocket = ;var io = ;var mockServer = io;var toListener = fixtureSocketrequestHandlerToListener;mockServer;
Or we can use storeToListeners helper to convert all CRUD fixture store request handlers into socket.io event listeners:
var listeners = fixtureSocket;mockServer;
FeathersJS is a minimalist, service-oriented, real-time web framework for modern applications. It is a NodeJS framework built on top of Express. It allows you to build REST-ful services and works with three providers: standard HTTP communication, WebSockets and Primus.
For example, given the following FeathersJS client app:
var socket = ;var app =;// Create FeathersJS CRUD service for "messages" resource:var messagesService = app;
We can simulate it with a can-fixture.store as follows:
var messagesStore = fixture;mockServer;
Now you can test your FeathersJS app:
With StealJS, you can import this module directly in a template that is autorendered:
jquery paths and the
global version of the plugin:
To make a build of the distributables into
dist/ in the cloned repository run
npm installnode build
Tests can run in the browser by opening a webserver and visiting the
Automated tests that run the tests from the command line in Firefox can be run with