UNPKG

pusher-js-mock

Version:

Mock Pusher.js in your JavaScript tests with ease

40 lines (39 loc) 1.7 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var proxy_channel_1 = require("./proxy-channel"); var proxy_presence_channel_1 = require("./proxy-presence-channel"); var pusher_channel_mock_1 = require("./pusher-channel-mock"); var pusher_js_mock_1 = require("./pusher-js-mock"); var pusher_presence_channel_mock_1 = require("./pusher-presence-channel-mock"); var PusherMockInstance = /** @class */ (function () { function PusherMockInstance() { this.channels = {}; this.connection = new pusher_channel_mock_1.default("connection"); this.channel = this.channel.bind(this); } /** * Get channel by its name. * @param {String} name - name of the channel. * @returns {PusherChannelMock} PusherChannelMock object that represents channel */ PusherMockInstance.prototype.channel = function (name, client) { if (client === void 0) { client = new pusher_js_mock_1.default(); } var presenceChannel = name.startsWith("presence-"); if (!this.channels[name]) { this.channels[name] = presenceChannel ? new pusher_presence_channel_mock_1.default(name) : new pusher_channel_mock_1.default(name); } return presenceChannel ? proxy_presence_channel_1.proxyPresenceChannel(this.channels[name], client) : proxy_channel_1.proxyChannel(this.channels[name], client); }; /** * Resets the instance to a fresh state, i.e. no channels. */ PusherMockInstance.prototype.reset = function () { this.channels = {}; }; return PusherMockInstance; }()); exports.default = new PusherMockInstance();