MCPcopy Index your code
hub / github.com/callstack/react-native-testing-library / matches

Function matches

src/matches.ts:9–30  ·  view source on GitHub ↗
(
  matcher: TextMatch,
  text: string | undefined,
  normalizer: NormalizerFn = getDefaultNormalizer(),
  exact: boolean = true,
)

Source from the content-addressed store, hash-verified

7};
8
9export function matches(
10 matcher: TextMatch,
11 text: string | undefined,
12 normalizer: NormalizerFn = getDefaultNormalizer(),
13 exact: boolean = true,
14): boolean {
15 if (typeof text !== 'string') {
16 return false;
17 }
18
19 const normalizedText = normalizer(text);
20 if (typeof matcher === 'string') {
21 const normalizedMatcher = normalizer(matcher);
22 return exact
23 ? normalizedText === normalizedMatcher
24 : normalizedText.toLowerCase().includes(normalizedMatcher.toLowerCase());
25 } else {
26 // Reset state for global regexes: https://stackoverflow.com/a/1520839/484499
27 matcher.lastIndex = 0;
28 return matcher.test(normalizedText);
29 }
30}
31
32type NormalizerConfig = {
33 trim?: boolean;

Callers 10

matchDisplayValueFunction · 0.90
matchPlaceholderTextFunction · 0.90
matchTestIdFunction · 0.90
getInstanceByHintTextFunction · 0.90
matchTextContentFunction · 0.90
matchAccessibilityLabelFunction · 0.90
toHaveTextContentFunction · 0.90
toHaveAccessibleNameFunction · 0.90
toHaveDisplayValueFunction · 0.90

Calls 1

getDefaultNormalizerFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…