pusher-js-mock
Mock Pusher.js in your JavaScript tests with ease
Installing
Using yarn:
yarn add --dev pusher-js-mock
Or using npm:
npm install -D pusher-js-mock
Example usage
Using PusherMock to mock Pusher client instance
If you need to mock a Pusher object in your tests that can
subscribe to channel, it's best to use PusherMock.
import { PusherMock } from "pusher-js-mock";
const pusher = new PusherMock()
const channel = pusher.subscribe("my-channel")
channel.emit("event-name")
Using PusherFactoryMock to mock Pusher Factory
If you're attaching a PusherFactory to a window
object like this:
window.PusherFactory = {
pusherClient: function(pusherKey) {
return new Pusher(pusherKey);
}
};
It's best for you to use PusherFactoryMock.
import { PusherFactoryMock } from "pusher-js-mock";
const pusherFactoryMock = new PusherFactoryMock();
window.PusherFactory = pusherFactoryMock;
pusher = pusherFactoryMock.pusherClient()
API 📦
Check out project docs on the information about API of the used
classes.
Credits
Photo by Octavian Rosca on Unsplash