UNPKG

rx-player

Version:
80 lines (79 loc) 3.03 kB
"use strict"; var __values = (this && this.__values) || function(o) { var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; if (m) return m.call(o); if (o && typeof o.length === "number") return { next: function () { if (o && i >= o.length) o = void 0; return { value: o && o[i++], done: !o }; } }; throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); }; var __read = (this && this.__read) || function (o, n) { var m = typeof Symbol === "function" && o[Symbol.iterator]; if (!m) return o; var i = m.call(o), r, ar = [], e; try { while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); } catch (error) { e = { error: error }; } finally { try { if (r && !r.done && (m = i["return"])) m.call(i); } finally { if (e) throw e.error; } } return ar; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.makeMockedClass = makeMockedClass; /** * Util useful to create mocked versions of classes with each of their methods * and properties replaced, while being properly checked by TypeScript. * @param {Object} methods - Each of this class' methods (key is the method * name, value is the implementation). * @param {Object} properties - Each of this class' property (key is the * property name, value is the implementation). * @returns {*} - The mocked class, which should respect its public API. */ function makeMockedClass(methods, properties) { var e_1, _a; // eslint-disable-next-line @typescript-eslint/no-extraneous-class var Dummy = /** @class */ (function () { function Dummy(opts) { if (opts === void 0) { opts = {}; } // Apply default property values for (var key in properties) { if (Object.prototype.hasOwnProperty.call(properties, key)) { // @ts-expect-error dynamic assignment // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment this[key] = properties[key]; } } // Override with any provided opts for (var key in opts) { if (Object.prototype.hasOwnProperty.call(opts, key)) { // @ts-expect-error dynamic assignment this[key] = opts[key]; } } } return Dummy; }()); try { for (var _b = __values(Object.entries(methods)), _c = _b.next(); !_c.done; _c = _b.next()) { var _d = __read(_c.value, 2), name_1 = _d[0], fn = _d[1]; // @ts-expect-error dynamic assignment Dummy.prototype[name_1] = fn; } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (_c && !_c.done && (_a = _b.return)) _a.call(_b); } finally { if (e_1) throw e_1.error; } } return Dummy; }