1 | import _ from './wrap/lodash'
|
2 | import isMatcher from './matchers/is-matcher'
|
3 |
|
4 | export default (expectedArgs, actualArgs, config = {}) => {
|
5 | if (arityMismatch(expectedArgs, actualArgs, config)) {
|
6 | return false
|
7 | } else if (config.allowMatchers !== false) {
|
8 | return equalsWithMatchers(expectedArgs, actualArgs)
|
9 | } else {
|
10 | return _.isEqual(expectedArgs, actualArgs)
|
11 | }
|
12 | }
|
13 |
|
14 | const arityMismatch = (expectedArgs, actualArgs, config) =>
|
15 | expectedArgs.length !== actualArgs.length && !config.ignoreExtraArgs
|
16 |
|
17 | const equalsWithMatchers = (expectedArgs, actualArgs) =>
|
18 | _.every(expectedArgs, (expectedArg, key) =>
|
19 | argumentMatchesExpectation(expectedArg, actualArgs[key]))
|
20 |
|
21 | const argumentMatchesExpectation = (expectedArg, actualArg) => {
|
22 | if (isMatcher(expectedArg)) {
|
23 | return matcherTestFor(expectedArg)(actualArg)
|
24 | } else {
|
25 | return _.isEqualWith(expectedArg, actualArg, (expectedEl, actualEl) => {
|
26 | if (isMatcher(expectedEl)) {
|
27 | return matcherTestFor(expectedEl)(actualEl)
|
28 | }
|
29 | })
|
30 | }
|
31 | }
|
32 |
|
33 | const matcherTestFor = (matcher) =>
|
34 | matcher.__matches
|