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