# All files / src/helpers/matchers matchTextContent.ts

100% Statements 3/3
0% Branches 0/1
100% Functions 1/1
100% Lines 3/3

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21

    435x
    435x
    435x

     import type { ReactTestInstance } from 'react-test-renderer';
    import { matches, TextMatch, TextMatchOptions } from '../../matches';
    import { getTextContent } from '../getTextContent';

    /**
     * Matches the given node's text content against string or regex matcher.
     *
     * @param node - Node which text content will be matched
     * @param text - The string or regex to match.
     * @returns - Whether the node's text content matches the given string or regex.
     */
    export function matchTextContent(
      node: ReactTestInstance,
      text: TextMatch,
      options: TextMatchOptions = {}
    ) {
      const textContent = getTextContent(node);
      const { exact, normalizer } = options;
      return matches(text, textContent, normalizer, exact);
    }