all files / core/spying/ spy.js

40% Statements 10/25
0% Branches 0/4
14.29% Functions 1/7
40% Lines 10/25
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                                                           
"use strict";
var spy_call_1 = require("./spy-call");
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 spy_call_1.SpyCall(args));
        var returnValue;
        if (!this._isStubbed) {
            returnValue = this._originalFunction.apply(this._originalContext, args);
        }
        if (this._hasReturnValue) {
            return this._returnValue;
        }
        return returnValue;
    };
    Spy.prototype.return = function (returnValue) {
        this._returnValue = returnValue;
        this._hasReturnValue = true;
    };
    Spy.prototype.andCallThrough = function () {
        this._isStubbed = false;
    };
    Spy.prototype.andStub = function () {
        this._isStubbed = true;
    };
    return Spy;
}());
exports.Spy = Spy;
//# sourceMappingURL=spy.js.map