()
| 591 | }; |
| 592 | |
| 593 | const createToHaveBeenCalledWithMatcher = (): MatcherFunction<Array<unknown>> => |
| 594 | function (received: any, ...expected): SyncExpectationResult { |
| 595 | const expectedArgument = '...expected'; |
| 596 | const options: MatcherHintOptions = { |
| 597 | isNot: this.isNot, |
| 598 | promise: this.promise, |
| 599 | }; |
| 600 | ensureMockOrSpy( |
| 601 | received, |
| 602 | 'toHaveBeenCalledWith', |
| 603 | expectedArgument, |
| 604 | options, |
| 605 | ); |
| 606 | |
| 607 | const receivedIsSpy = isSpy(received); |
| 608 | const receivedName = receivedIsSpy ? 'spy' : received.getMockName(); |
| 609 | |
| 610 | const calls = receivedIsSpy |
| 611 | ? received.calls.all().map((x: any) => x.args) |
| 612 | : received.mock.calls; |
| 613 | |
| 614 | const pass = calls.some((call: any) => isEqualCall(expected, call)); |
| 615 | |
| 616 | const message = pass |
| 617 | ? () => { |
| 618 | // Some examples of calls that are equal to expected value. |
| 619 | const indexedCalls: Array<IndexedCall> = []; |
| 620 | let i = 0; |
| 621 | while (i < calls.length && indexedCalls.length < PRINT_LIMIT) { |
| 622 | if (isEqualCall(expected, calls[i])) { |
| 623 | indexedCalls.push([i, calls[i]]); |
| 624 | } |
| 625 | i += 1; |
| 626 | } |
| 627 | |
| 628 | return ( |
| 629 | // eslint-disable-next-line prefer-template |
| 630 | matcherHint( |
| 631 | 'toHaveBeenCalledWith', |
| 632 | receivedName, |
| 633 | expectedArgument, |
| 634 | options, |
| 635 | ) + |
| 636 | '\n\n' + |
| 637 | `Expected: not ${printExpectedArgs(expected)}\n` + |
| 638 | (calls.length === 1 && stringify(calls[0]) === stringify(expected) |
| 639 | ? '' |
| 640 | : printReceivedCallsNegative( |
| 641 | expected, |
| 642 | indexedCalls, |
| 643 | calls.length === 1, |
| 644 | )) + |
| 645 | `\nNumber of calls: ${printReceived(calls.length)}` |
| 646 | ); |
| 647 | } |
| 648 | : () => { |
| 649 | // Some examples of calls that are not equal to expected value. |
| 650 | const indexedCalls: Array<IndexedCall> = []; |
no test coverage detected