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