Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

pusher-js-mock

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pusher-js-mock - npm Package Compare versions

Comparing version 0.3.2 to 0.3.3

1

lib/pusher-js-mock-instance.d.ts

@@ -8,2 +8,3 @@ import PusherMock from "./pusher-js-mock";

channels: IChannels;
connection: any;
constructor();

@@ -10,0 +11,0 @@ /**

@@ -10,2 +10,3 @@ "use strict";

this.channels = {};
this.connection = new pusher_channel_mock_1.default("connection");
this.channel = this.channel.bind(this);

@@ -12,0 +13,0 @@ }

@@ -13,2 +13,3 @@ import { PusherChannelMock } from ".";

config: IPusherMockOptions | undefined;
connection: any;
channels: import("./pusher-js-mock-instance").IChannels;

@@ -15,0 +16,0 @@ channel: (name: string, client?: PusherMock) => any;

@@ -11,2 +11,3 @@ "use strict";

this.info = undefined;
this.connection = pusher_js_mock_instance_1.default.connection;
this.channels = pusher_js_mock_instance_1.default.channels;

@@ -13,0 +14,0 @@ this.channel = pusher_js_mock_instance_1.default.channel;

2

package.json
{
"name": "pusher-js-mock",
"version": "0.3.2",
"version": "0.3.3",
"description": "Mock Pusher.js in your JavaScript tests with ease",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -45,3 +45,5 @@ <p align="center">

- [Emitting an event 📶](#emitting-an-event-📶)
- [Listening for an events 👂](#listening-for-an-event-👂)
- [Listening for an event 👂](#listening-for-an-event-👂)
- [Emitting an event from connection 📶](#emitting-an-event-from-connection-📶)
- [Listening for an event from connection 👂](#listening-for-an-event-from-connection-👂)
- [Stubbing Pusher when imported from pusher-js package 📦](#stubbing-pusher-when-imported-from-pusher-js-package-📦)

@@ -85,3 +87,3 @@ - [Stubbing Pusher when used as a global variable 🌍](#stubbing-pusher-when-used-as-a-global-variable-🌍)

descibe('listening for an event', () => {
descibe("listening for an event", () => {
// initializing PusherMock

@@ -94,4 +96,4 @@ const pusher = new PusherMock();

// define and attach a listener
const listener = jest.fn()
channel.bind('event-name', listener)
const listener = jest.fn();
channel.bind("event-name", listener);

@@ -102,6 +104,43 @@ // emitting an event

// Expect listener to have been called
expect(listener).toHaveBeenCalled()
})
expect(listener).toHaveBeenCalled();
});
```
### Emitting an event from connection 📶
The connection within pusher is mocked and can be used much like a channel channel. There's no need to subscribe to subscription as it's subscribed by default on pusher.
```javascript
import { PusherMock } from "pusher-js-mock";
// initializing PusherMock
const pusher = new PusherMock();
// emitting connection event
pusher.connection.emit("event-name");
```
### Listening for an event from connection 👂
As with channels, you can also listen to connection for events.
```javascript
import { PusherMock } from "pusher-js-mock";
descibe("listening for an event", () => {
// initializing PusherMock
const pusher = new PusherMock();
// define and attach a listener
const listener = jest.fn();
pusher.connection.bind("event-name", listener);
// emitting an event
pusher.connection.emit("event-name");
// Expect listener to have been called
expect(listener).toHaveBeenCalled();
});
```
### Stubbing Pusher when imported from pusher-js package 📦

@@ -108,0 +147,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc