()
| 677 | }; |
| 678 | |
| 679 | const createToHaveReturnedWithMatcher = (): MatcherFunction<[unknown]> => |
| 680 | function (received: any, expected): SyncExpectationResult { |
| 681 | const expectedArgument = 'expected'; |
| 682 | const options: MatcherHintOptions = { |
| 683 | isNot: this.isNot, |
| 684 | promise: this.promise, |
| 685 | }; |
| 686 | ensureMock(received, 'toHaveReturnedWith', expectedArgument, options); |
| 687 | |
| 688 | const receivedName = received.getMockName(); |
| 689 | const {calls, results} = received.mock; |
| 690 | |
| 691 | const pass = results.some((result: any) => isEqualReturn(expected, result)); |
| 692 | |
| 693 | const message = pass |
| 694 | ? () => { |
| 695 | // Some examples of results that are equal to expected value. |
| 696 | const indexedResults: Array<IndexedResult> = []; |
| 697 | let i = 0; |
| 698 | while (i < results.length && indexedResults.length < PRINT_LIMIT) { |
| 699 | if (isEqualReturn(expected, results[i])) { |
| 700 | indexedResults.push([i, results[i]]); |
| 701 | } |
| 702 | i += 1; |
| 703 | } |
| 704 | |
| 705 | return ( |
| 706 | // eslint-disable-next-line prefer-template |
| 707 | matcherHint( |
| 708 | 'toHaveReturnedWith', |
| 709 | receivedName, |
| 710 | expectedArgument, |
| 711 | options, |
| 712 | ) + |
| 713 | '\n\n' + |
| 714 | `Expected: not ${printExpected(expected)}\n` + |
| 715 | (results.length === 1 && |
| 716 | results[0].type === 'return' && |
| 717 | stringify(results[0].value) === stringify(expected) |
| 718 | ? '' |
| 719 | : printReceivedResults( |
| 720 | 'Received: ', |
| 721 | expected, |
| 722 | indexedResults, |
| 723 | results.length === 1, |
| 724 | )) + |
| 725 | printNumberOfReturns(countReturns(results), calls.length) |
| 726 | ); |
| 727 | } |
| 728 | : () => { |
| 729 | // Some examples of results that are not equal to expected value. |
| 730 | const indexedResults: Array<IndexedResult> = []; |
| 731 | let i = 0; |
| 732 | while (i < results.length && indexedResults.length < PRINT_LIMIT) { |
| 733 | indexedResults.push([i, results[i]]); |
| 734 | i += 1; |
| 735 | } |
| 736 |
no test coverage detected