1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const lodash_1 = require("../wrap/lodash");
|
4 | const args_match_1 = require("../args-match");
|
5 | const index_1 = require("./index");
|
6 | let callHistory = [];
|
7 | index_1.default.onReset(() => { callHistory = []; });
|
8 | exports.default = {
|
9 | log(testDouble, args, context) {
|
10 | index_1.default.for(testDouble).calls.push({ args, context, cloneArgs: lodash_1.default.cloneDeep(args) });
|
11 | return callHistory.push({ testDouble, args, context });
|
12 | },
|
13 | pop() {
|
14 | return lodash_1.default.tap(callHistory.pop(), function (call) {
|
15 | if (call != null) {
|
16 | index_1.default.for(call.testDouble).calls.pop();
|
17 | }
|
18 | });
|
19 | },
|
20 | wasInvoked(testDouble, args, config) {
|
21 | const matchingInvocationCount = this.where(testDouble, args, config).length;
|
22 | if (config.times != null) {
|
23 | return matchingInvocationCount === config.times;
|
24 | }
|
25 | else {
|
26 | return matchingInvocationCount > 0;
|
27 | }
|
28 | },
|
29 | where(testDouble, args, config) {
|
30 | return lodash_1.default.filter(index_1.default.for(testDouble).calls, function (call) {
|
31 | const pastArgs = config.cloneArgs ? call.cloneArgs : call.args;
|
32 | return args_match_1.default(args, pastArgs, config);
|
33 | });
|
34 | },
|
35 | for(testDouble) {
|
36 | return index_1.default.for(testDouble).calls;
|
37 | }
|
38 | };
|