"use strict";
var _namespace_1 = require("./_namespace");
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 _namespace_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 |