(received: ContainIterable | string, expected: unknown)
| 912 | }, |
| 913 | |
| 914 | toContain(received: ContainIterable | string, expected: unknown) { |
| 915 | const matcherName = 'toContain'; |
| 916 | const isNot = this.isNot; |
| 917 | const options: MatcherHintOptions = { comment: 'indexOf', isNot, promise: this.promise }; |
| 918 | |
| 919 | if (received === null || received === undefined) { |
| 920 | throw new Error( |
| 921 | matcherErrorMessage( |
| 922 | matcherHint(matcherName, undefined, undefined, options), |
| 923 | `${RECEIVED_COLOR('received')} value must not be null nor undefined`, |
| 924 | printWithType('Received', received, printReceived), |
| 925 | ), |
| 926 | ); |
| 927 | } |
| 928 | |
| 929 | if (typeof received === 'string') { |
| 930 | const wrongTypeErrorMessage = `${EXPECTED_COLOR('expected')} value must be a string if ${RECEIVED_COLOR('received')} value is a string`; |
| 931 | |
| 932 | if (typeof expected !== 'string') { |
| 933 | throw new TypeError( |
| 934 | matcherErrorMessage( |
| 935 | matcherHint(matcherName, received, String(expected), options), |
| 936 | wrongTypeErrorMessage, |
| 937 | printWithType('Expected', expected, printExpected) + |
| 938 | '\n' + |
| 939 | printWithType('Received', received, printReceived), |
| 940 | ), |
| 941 | ); |
| 942 | } |
| 943 | |
| 944 | const index = received.indexOf(String(expected)); |
| 945 | const pass = index !== -1; |
| 946 | |
| 947 | const message = () => { |
| 948 | const labelExpected = `Expected ${typeof expected === 'string' ? 'substring' : 'value'}`; |
| 949 | const labelReceived = 'Received string'; |
| 950 | const printLabel = getLabelPrinter(labelExpected, labelReceived); |
| 951 | |
| 952 | return ( |
| 953 | matcherHint(matcherName, undefined, undefined, options) + |
| 954 | '\n\n' + |
| 955 | `${printLabel(labelExpected)}${isNot ? 'not ' : ''}${printExpected(expected)}\n` + |
| 956 | `${printLabel(labelReceived)}${isNot ? ' ' : ''}${ |
| 957 | isNot |
| 958 | ? printReceivedStringContainExpectedSubstring(received, index, String(expected).length) |
| 959 | : printReceived(received) |
| 960 | }` |
| 961 | ); |
| 962 | }; |
| 963 | |
| 964 | return { message, pass }; |
| 965 | } |
| 966 | |
| 967 | const indexable = [...received]; |
| 968 | const index = indexable.indexOf(expected); |
| 969 | const pass = index !== -1; |
| 970 | |
| 971 | const message = () => { |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…