pusher-js-mock
Version:
Mock Pusher.js in your JavaScript tests with ease
45 lines (44 loc) • 1.51 kB
TypeScript
import PusherMock from "./pusher-js-mock";
/** Interface for all the callbacks each Pusher event could potentially have */
interface ICallbacks {
[key: string]: Array<() => void>;
}
/** Class representing a fake Pusher channel. */
declare class PusherChannelMock {
name: string;
callbacks: ICallbacks;
subscribed: boolean;
IS_PROXY?: boolean;
pusher?: PusherMock;
/** Initialize PusherChannelMock with callbacks object. */
constructor(name?: string);
/**
* Bind callback to an event name.
* @param {String} name - name of the event.
* @param {Function} callback - callback to be called on event.
*/
bind(name: string, callback: () => void): this;
/**
* Unbind callback from an event name.
* @param {String} name - name of the event.
* @param {Function} callback - callback to be called on event.
*/
unbind(name: string, callback: () => void): this;
/**
* Unbind callbacks from all the events.
*/
unbind_all(): this;
/**
* Emit event with data.
* @param {String} name - name of the event.
* @param {*} data - data you want to pass in to callback function that gets called.
*/
emit(name: string, data?: any): this;
/**
* Trigger event with data.
* @param {String} name - name of the event.
* @param {*} data - data you want to pass in to callback function that gets called.
*/
trigger(name: string, data?: any): void;
}
export default PusherChannelMock;