UNPKG

1.32 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const lodash_1 = require("./wrap/lodash");
4const is_matcher_1 = require("./matchers/is-matcher");
5exports.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};
16const arityMismatch = (expectedArgs, actualArgs, config) => expectedArgs.length !== actualArgs.length && !config.ignoreExtraArgs;
17const equalsWithMatchers = (expectedArgs, actualArgs) => lodash_1.default.every(expectedArgs, (expectedArg, key) => argumentMatchesExpectation(expectedArg, actualArgs[key]));
18const 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};
30const matcherTestFor = (matcher) => matcher.__matches;