1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const lodash_1 = require("./wrap/lodash");
|
4 | const is_matcher_1 = require("./matchers/is-matcher");
|
5 | exports.default = (expectedArgs, actualArgs, config = {}) => {
|
6 | if (arityMismatch(expectedArgs, actualArgs, config)) {
|
7 | return false;
|
8 | }
|
9 | else if (config.allowMatchers !== false) {
|
10 | return equalsWithMatchers(expectedArgs, actualArgs);
|
11 | }
|
12 | else {
|
13 | return lodash_1.default.isEqual(expectedArgs, actualArgs);
|
14 | }
|
15 | };
|
16 | const arityMismatch = (expectedArgs, actualArgs, config) => expectedArgs.length !== actualArgs.length && !config.ignoreExtraArgs;
|
17 | const equalsWithMatchers = (expectedArgs, actualArgs) => lodash_1.default.every(expectedArgs, (expectedArg, key) => argumentMatchesExpectation(expectedArg, actualArgs[key]));
|
18 | const argumentMatchesExpectation = (expectedArg, actualArg) => {
|
19 | if ((0, is_matcher_1.default)(expectedArg)) {
|
20 | return matcherTestFor(expectedArg)(actualArg);
|
21 | }
|
22 | else {
|
23 | return lodash_1.default.isEqualWith(expectedArg, actualArg, (expectedEl, actualEl) => {
|
24 | if ((0, is_matcher_1.default)(expectedEl)) {
|
25 | return matcherTestFor(expectedEl)(actualEl);
|
26 | }
|
27 | });
|
28 | }
|
29 | };
|
30 | const matcherTestFor = (matcher) => matcher.__matches;
|