( replacedExpected: unknown, replacedReceived: unknown, expectedCycles: Array<unknown>, receivedCycles: Array<unknown>, )
| 424 | } |
| 425 | |
| 426 | function _replaceMatchedToAsymmetricMatcher( |
| 427 | replacedExpected: unknown, |
| 428 | replacedReceived: unknown, |
| 429 | expectedCycles: Array<unknown>, |
| 430 | receivedCycles: Array<unknown>, |
| 431 | ) { |
| 432 | if (!Replaceable.isReplaceable(replacedExpected, replacedReceived)) { |
| 433 | return {replacedExpected, replacedReceived}; |
| 434 | } |
| 435 | |
| 436 | if ( |
| 437 | expectedCycles.includes(replacedExpected) || |
| 438 | receivedCycles.includes(replacedReceived) |
| 439 | ) { |
| 440 | return {replacedExpected, replacedReceived}; |
| 441 | } |
| 442 | |
| 443 | expectedCycles.push(replacedExpected); |
| 444 | receivedCycles.push(replacedReceived); |
| 445 | |
| 446 | const expectedReplaceable = new Replaceable(replacedExpected); |
| 447 | const receivedReplaceable = new Replaceable(replacedReceived); |
| 448 | |
| 449 | // eslint-disable-next-line unicorn/no-array-for-each |
| 450 | expectedReplaceable.forEach((expectedValue: unknown, key: unknown) => { |
| 451 | const receivedValue = receivedReplaceable.get(key); |
| 452 | if (isAsymmetricMatcher(expectedValue)) { |
| 453 | if (expectedValue.asymmetricMatch(receivedValue)) { |
| 454 | receivedReplaceable.set(key, expectedValue); |
| 455 | } |
| 456 | } else if (isAsymmetricMatcher(receivedValue)) { |
| 457 | if (receivedValue.asymmetricMatch(expectedValue)) { |
| 458 | expectedReplaceable.set(key, receivedValue); |
| 459 | } |
| 460 | } else if (Replaceable.isReplaceable(expectedValue, receivedValue)) { |
| 461 | const replaced = _replaceMatchedToAsymmetricMatcher( |
| 462 | expectedValue, |
| 463 | receivedValue, |
| 464 | expectedCycles, |
| 465 | receivedCycles, |
| 466 | ); |
| 467 | expectedReplaceable.set(key, replaced.replacedExpected); |
| 468 | receivedReplaceable.set(key, replaced.replacedReceived); |
| 469 | } |
| 470 | }); |
| 471 | |
| 472 | return { |
| 473 | replacedExpected: expectedReplaceable.object, |
| 474 | replacedReceived: receivedReplaceable.object, |
| 475 | }; |
| 476 | } |
| 477 | |
| 478 | type AsymmetricMatcher = { |
| 479 | asymmetricMatch: Function; |
no test coverage detected