all files / core/spying/ spy.js

100% Statements 32/32
100% Branches 6/6
100% Functions 8/8
100% Lines 32/32
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49  324× 324× 324×     5016×         4716× 4716× 4716× 196×   4520×   4716× 44×   4672×   44× 44×     167× 167×        
"use strict";
var _spying_1 = require("../_spying");
var Spy = (function () {
    function Spy(originalFunction, originalContext) {
        this._calls = [];
        this.originalFunction = originalFunction;
        this._originalContext = originalContext;
    }
    Object.defineProperty(Spy.prototype, "calls", {
        get: function () {
            return this._calls;
        },
        enumerable: true,
        configurable: true
    });
    Spy.prototype.call = function (args) {
        this.calls.push(new _spying_1.SpyCall(args));
        var returnValue;
        if (!this._isStubbed) {
            returnValue = this.originalFunction.apply(this._originalContext, args);
        }
        else if (this._fakeFunction) {
            this._fakeFunction.apply(this._originalContext, args);
        }
        if (this._hasReturnValue) {
            return this._returnValue;
        }
        return returnValue;
    };
    Spy.prototype.andReturn = function (returnValue) {
        this._returnValue = returnValue;
        this._hasReturnValue = true;
    };
    Spy.prototype.andCallThrough = function () {
        this._isStubbed = false;
        this._fakeFunction = undefined;
    };
    Spy.prototype.andStub = function () {
        this._isStubbed = true;
        this._fakeFunction = undefined;
    };
    Spy.prototype.andCall = function (fakeFunction) {
        this._isStubbed = true;
        this._fakeFunction = fakeFunction;
    };
    return Spy;
}());
exports.Spy = Spy;
//# sourceMappingURL=spy.js.map