UNPKG

1.46 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3var lodash_1 = require("./wrap/lodash");
4var is_matcher_1 = require("./matchers/is-matcher");
5exports.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});
17var arityMismatch = function (expectedArgs, actualArgs, config) {
18 return expectedArgs.length !== actualArgs.length && !config.ignoreExtraArgs;
19};
20var equalsWithMatchers = function (expectedArgs, actualArgs) {
21 return lodash_1.default.every(expectedArgs, function (expectedArg, key) {
22 return argumentMatchesExpectation(expectedArg, actualArgs[key]);
23 });
24};
25var 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};
37var matcherTestFor = function (matcher) {
38 return matcher.__matches;
39};