(received: ContainIterable, expected: unknown)
| 567 | }, |
| 568 | |
| 569 | toContainEqual(received: ContainIterable, expected: unknown) { |
| 570 | const matcherName = 'toContainEqual'; |
| 571 | const isNot = this.isNot; |
| 572 | const options: MatcherHintOptions = { |
| 573 | comment: 'deep equality', |
| 574 | isNot, |
| 575 | promise: this.promise, |
| 576 | }; |
| 577 | |
| 578 | if (received == null) { |
| 579 | throw new Error( |
| 580 | matcherErrorMessage( |
| 581 | matcherHint(matcherName, undefined, undefined, options), |
| 582 | `${RECEIVED_COLOR('received')} value must not be null nor undefined`, |
| 583 | printWithType('Received', received, printReceived), |
| 584 | ), |
| 585 | ); |
| 586 | } |
| 587 | |
| 588 | const index = [...received].findIndex(item => |
| 589 | equals(item, expected, [...this.customTesters, iterableEquality]), |
| 590 | ); |
| 591 | const pass = index !== -1; |
| 592 | |
| 593 | const message = () => { |
| 594 | const labelExpected = 'Expected value'; |
| 595 | const labelReceived = `Received ${getType(received)}`; |
| 596 | const printLabel = getLabelPrinter(labelExpected, labelReceived); |
| 597 | |
| 598 | return ( |
| 599 | // eslint-disable-next-line prefer-template |
| 600 | matcherHint(matcherName, undefined, undefined, options) + |
| 601 | '\n\n' + |
| 602 | `${printLabel(labelExpected)}${isNot ? 'not ' : ''}${printExpected( |
| 603 | expected, |
| 604 | )}\n` + |
| 605 | `${printLabel(labelReceived)}${isNot ? ' ' : ''}${ |
| 606 | isNot && Array.isArray(received) |
| 607 | ? printReceivedArrayContainExpectedItem(received, index) |
| 608 | : printReceived(received) |
| 609 | }` |
| 610 | ); |
| 611 | }; |
| 612 | |
| 613 | return {message, pass}; |
| 614 | }, |
| 615 | |
| 616 | toEqual(received: unknown, expected: unknown) { |
| 617 | const matcherName = 'toEqual'; |
nothing calls this directly
no test coverage detected