Mock Pusher.js in your JavaScript tests
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
docs
examples
src
.babelrc
.eslintrc
.gitignore
CODE_OF_CONDUCT.md
CONTRIBUTING.md
LICENSE
PULL_REQUEST_TEMPLATE.md
README.md
logo.jpg
package.json
yarn.lock

README.md

Build Status Code Climate Test Coverage Open Source Helpers

pusher-js-mock logo

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";

// initializing PusherMock
const pusher = new PusherMock()

// subscribing to a Pusher channel
const channel = pusher.subscribe("my-channel")

// emitting an event
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";

// initialize instance of PusherFactoryMock
const pusherFactoryMock = new PusherFactoryMock();
// replace it with the object that is attached to a window
window.PusherFactory = pusherFactoryMock;

// get the Pusher client reference
pusher = pusherFactoryMock.pusherClient()

API 📦

Check out project docs on the information about API of the used classes.

Code of Conduct

Contributing

Credits

Photo by Octavian Rosca on Unsplash