1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | var lodash_1 = require("./wrap/lodash");
|
4 | var calls_1 = require("./store/calls");
|
5 | var store_1 = require("./store");
|
6 | var stubbings_1 = require("./store/stubbings");
|
7 | var imitate_1 = require("./imitate");
|
8 | function func(nameOrFunc, __optionalName) {
|
9 | return lodash_1.default.isFunction(nameOrFunc)
|
10 | ? imitate_1.default(nameOrFunc)
|
11 | : createTestDoubleNamed(nameOrFunc || __optionalName);
|
12 | }
|
13 | exports.default = func;
|
14 | var createTestDoubleNamed = function (name) {
|
15 | return lodash_1.default.tap(createTestDoubleFunction(), function (testDouble) {
|
16 | var entry = store_1.default.for(testDouble, true);
|
17 | if (name != null) {
|
18 | entry.name = name;
|
19 | testDouble.toString = function () { return "[test double for \"" + name + "\"]"; };
|
20 | }
|
21 | else {
|
22 | testDouble.toString = function () { return '[test double (unnamed)]'; };
|
23 | }
|
24 | });
|
25 | };
|
26 | var createTestDoubleFunction = function () {
|
27 | return function testDouble() {
|
28 | var args = [];
|
29 | for (var _i = 0; _i < arguments.length; _i++) {
|
30 | args[_i] = arguments[_i];
|
31 | }
|
32 | calls_1.default.log(testDouble, args, this);
|
33 | return stubbings_1.default.invoke(testDouble, args, this);
|
34 | };
|
35 | };
|