()
| 412 | }; |
| 413 | |
| 414 | const createToHaveReturnedMatcher = (): MatcherFunction<[unknown]> => |
| 415 | function (received: any, expected): SyncExpectationResult { |
| 416 | const expectedArgument = ''; |
| 417 | const options: MatcherHintOptions = { |
| 418 | isNot: this.isNot, |
| 419 | promise: this.promise, |
| 420 | }; |
| 421 | ensureNoExpected(expected, 'toHaveReturned', options); |
| 422 | ensureMock(received, 'toHaveReturned', expectedArgument, options); |
| 423 | |
| 424 | const receivedName = received.getMockName(); |
| 425 | |
| 426 | // Count return values that correspond only to calls that returned |
| 427 | const count = received.mock.results.reduce( |
| 428 | (n: number, result: any) => (result.type === 'return' ? n + 1 : n), |
| 429 | 0, |
| 430 | ); |
| 431 | |
| 432 | const pass = count > 0; |
| 433 | |
| 434 | const message = pass |
| 435 | ? () => |
| 436 | // eslint-disable-next-line prefer-template |
| 437 | matcherHint( |
| 438 | 'toHaveReturned', |
| 439 | receivedName, |
| 440 | expectedArgument, |
| 441 | options, |
| 442 | ) + |
| 443 | '\n\n' + |
| 444 | `Expected number of returns: ${printExpected(0)}\n` + |
| 445 | `Received number of returns: ${printReceived(count)}\n\n` + |
| 446 | received.mock.results |
| 447 | .reduce((lines: Array<string>, result: any, i: number) => { |
| 448 | if (result.type === 'return' && lines.length < PRINT_LIMIT) { |
| 449 | lines.push(`${i + 1}: ${printReceived(result.value)}`); |
| 450 | } |
| 451 | |
| 452 | return lines; |
| 453 | }, []) |
| 454 | .join('\n') + |
| 455 | (received.mock.calls.length === count |
| 456 | ? '' |
| 457 | : `\n\nReceived number of calls: ${printReceived( |
| 458 | received.mock.calls.length, |
| 459 | )}`) |
| 460 | : () => |
| 461 | // eslint-disable-next-line prefer-template |
| 462 | matcherHint( |
| 463 | 'toHaveReturned', |
| 464 | receivedName, |
| 465 | expectedArgument, |
| 466 | options, |
| 467 | ) + |
| 468 | '\n\n' + |
| 469 | `Expected number of returns: >= ${printExpected(1)}\n` + |
| 470 | `Received number of returns: ${printReceived(count)}` + |
| 471 | (received.mock.calls.length === count |
no test coverage detected