UNPKG

alsatian

Version:

TypeScript and JavaScript testing framework for beautiful and readable tests

34 lines 1.22 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const spying_1 = require("../spying"); const expose_spy_functions_1 = require("./expose-spy-functions"); class RestorableFunctionSpy extends spying_1.FunctionSpy { constructor(target, functionName) { super(); this._originalFunction = target[functionName]; this.context = target; this._functionName = functionName; this._target = target; target[functionName] = this.call.bind(this); expose_spy_functions_1.exposeSpyFunctions(target[functionName], this); target[functionName].restore = this.restore.bind(this); } restore() { this._target[this._functionName] = this._originalFunction; } andCallThrough() { this.isStubbed = false; } andStub() { this.isStubbed = true; } call(...args) { const returnValue = super.call.apply(this, args); if (!this.isStubbed && !this.hasReturnValue) { return this._originalFunction.apply(this.context, args); } return returnValue; } } exports.RestorableFunctionSpy = RestorableFunctionSpy; //# sourceMappingURL=restorable-function-spy.js.map