(received: ContainIterable | string, expected: unknown)
| 463 | }, |
| 464 | |
| 465 | toContain(received: ContainIterable | string, expected: unknown) { |
| 466 | const matcherName = 'toContain'; |
| 467 | const isNot = this.isNot; |
| 468 | const options: MatcherHintOptions = { |
| 469 | comment: 'indexOf', |
| 470 | isNot, |
| 471 | promise: this.promise, |
| 472 | }; |
| 473 | |
| 474 | if (received == null) { |
| 475 | throw new Error( |
| 476 | matcherErrorMessage( |
| 477 | matcherHint(matcherName, undefined, undefined, options), |
| 478 | `${RECEIVED_COLOR('received')} value must not be null nor undefined`, |
| 479 | printWithType('Received', received, printReceived), |
| 480 | ), |
| 481 | ); |
| 482 | } |
| 483 | |
| 484 | if (typeof received === 'string') { |
| 485 | const wrongTypeErrorMessage = `${EXPECTED_COLOR( |
| 486 | 'expected', |
| 487 | )} value must be a string if ${RECEIVED_COLOR( |
| 488 | 'received', |
| 489 | )} value is a string`; |
| 490 | |
| 491 | if (typeof expected !== 'string') { |
| 492 | throw new TypeError( |
| 493 | matcherErrorMessage( |
| 494 | matcherHint(matcherName, received, String(expected), options), |
| 495 | wrongTypeErrorMessage, |
| 496 | // eslint-disable-next-line prefer-template |
| 497 | printWithType('Expected', expected, printExpected) + |
| 498 | '\n' + |
| 499 | printWithType('Received', received, printReceived), |
| 500 | ), |
| 501 | ); |
| 502 | } |
| 503 | |
| 504 | const index = received.indexOf(String(expected)); |
| 505 | const pass = index !== -1; |
| 506 | |
| 507 | const message = () => { |
| 508 | const labelExpected = `Expected ${ |
| 509 | typeof expected === 'string' ? 'substring' : 'value' |
| 510 | }`; |
| 511 | const labelReceived = 'Received string'; |
| 512 | const printLabel = getLabelPrinter(labelExpected, labelReceived); |
| 513 | |
| 514 | return ( |
| 515 | // eslint-disable-next-line prefer-template |
| 516 | matcherHint(matcherName, undefined, undefined, options) + |
| 517 | '\n\n' + |
| 518 | `${printLabel(labelExpected)}${isNot ? 'not ' : ''}${printExpected( |
| 519 | expected, |
| 520 | )}\n` + |
| 521 | `${printLabel(labelReceived)}${isNot ? ' ' : ''}${ |
| 522 | isNot |
nothing calls this directly
no test coverage detected