|
1 | 1 | import {wrapAllByQueryWithSuggestion} from '../query-helpers'
|
2 | 2 | import {checkContainerType} from '../helpers'
|
3 | 3 | import {DEFAULT_IGNORE_TAGS} from '../shared'
|
4 |
| -import {AllByText, GetErrorFunction} from '../../types' |
| 4 | +import { |
| 5 | + AllByText, |
| 6 | + GetErrorFunction, |
| 7 | + SelectorMatcherOptions, |
| 8 | + Matcher, |
| 9 | +} from '../../types' |
5 | 10 | import {
|
6 | 11 | fuzzyMatches,
|
7 | 12 | matches,
|
@@ -42,8 +47,21 @@ const queryAllByText: AllByText = (
|
42 | 47 |
|
43 | 48 | const getMultipleError: GetErrorFunction<[unknown]> = (c, text) =>
|
44 | 49 | `Found multiple elements with the text: ${text}`
|
45 |
| -const getMissingError: GetErrorFunction<[unknown]> = (c, text) => |
46 |
| - `Unable to find an element with the text: ${text}. This could be because the text is broken up by multiple elements. In this case, you can provide a function for your text matcher to make your matcher more flexible.` |
| 50 | +const getMissingError: GetErrorFunction<[Matcher, SelectorMatcherOptions]> = ( |
| 51 | + c, |
| 52 | + text, |
| 53 | + options = {}, |
| 54 | +) => { |
| 55 | + const {collapseWhitespace, trim, normalizer} = options |
| 56 | + const matchNormalizer = makeNormalizer({collapseWhitespace, trim, normalizer}) |
| 57 | + const normalizedText = matchNormalizer(text.toString()) |
| 58 | + const isNormalizedDifferent = normalizedText !== text.toString() |
| 59 | + return `Unable to find an element with the text: ${ |
| 60 | + isNormalizedDifferent |
| 61 | + ? `${normalizedText} (normalized from '${text}')` |
| 62 | + : text |
| 63 | + }. This could be because the text is broken up by multiple elements. In this case, you can provide a function for your text matcher to make your matcher more flexible.` |
| 64 | +} |
47 | 65 |
|
48 | 66 | const queryAllByTextWithSuggestions = wrapAllByQueryWithSuggestion<
|
49 | 67 | // @ts-expect-error -- See `wrapAllByQueryWithSuggestion` Argument constraint comment
|
|
0 commit comments