pusher-js-mock
Version:
Mock Pusher.js in your JavaScript tests with ease
31 lines (30 loc) • 1.04 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.proxyChannel = void 0;
/**
* Create the proxied channel
* @param {PusherChannelMock} channel the channel to be proxied
* @param {PusherMock} client the client we'll use to proxy the channel
* @returns {Proxy<PusherChannelMock>} the proxied channel
*/
exports.proxyChannel = function (channel, client) {
var handler = {
/**
* Proxies a channel and augments it with client specific information
* @param target The channel we're proxying
* @param key The attribute, property or method we're trapping
* @returns {mixed} the result of the trapped function
*/
get: function (target, key) {
switch (key) {
case "IS_PROXY":
return true;
case "pusher":
return client;
default:
return target[key];
}
}
};
return new Proxy(channel, handler);
};