UNPKG

1.17 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const lodash_1 = require("./wrap/lodash");
4const calls_1 = require("./store/calls");
5const store_1 = require("./store");
6const stubbings_1 = require("./store/stubbings");
7const imitate_1 = require("./imitate");
8function func(nameOrFunc, __optionalName) {
9 return lodash_1.default.isFunction(nameOrFunc)
10 ? (0, imitate_1.default)(nameOrFunc)
11 : createTestDoubleNamed(nameOrFunc || __optionalName);
12}
13exports.default = func;
14const 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};
26const 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};