# All files / src/queries labelText.ts

100% Statements 10/10
100% Branches 2/2
100% Functions 6/6
100% Lines 10/10

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
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60

    539x
    169x

    1879x

    48x
    22x
    48x
    108x

    48x

    48x

    386x

     import type { ReactTestInstance } from 'react-test-renderer';
    import { findAll } from '../helpers/findAll';
    import { TextMatch, TextMatchOptions } from '../matches';
    import { matchLabelText } from '../helpers/matchers/matchLabelText';
    import { makeQueries } from './makeQueries';
    import type {
      FindAllByQuery,
      FindByQuery,
      GetAllByQuery,
      GetByQuery,
      QueryAllByQuery,
      QueryByQuery,
    } from './makeQueries';
    import { CommonQueryOptions } from './options';

    type ByLabelTextOptions = CommonQueryOptions & TextMatchOptions;

    function queryAllByLabelText(instance: ReactTestInstance) {
      return (text: TextMatch, queryOptions?: ByLabelTextOptions) => {
        return findAll(
          instance,
          (node) =>
            typeof node.type === 'string' &&
            matchLabelText(instance, node, text, queryOptions),
          queryOptions
        );
      };
    }

    const getMultipleError = (labelText: TextMatch) =>
      `Found multiple elements with accessibilityLabel: ${String(labelText)} `;
    const getMissingError = (labelText: TextMatch) =>
      `Unable to find an element with accessibilityLabel: ${String(labelText)}`;

    const { getBy, getAllBy, queryBy, queryAllBy, findBy, findAllBy } = makeQueries(
      queryAllByLabelText,
      getMissingError,
      getMultipleError
    );

    export type ByLabelTextQueries = {
      getByLabelText: GetByQuery<TextMatch, ByLabelTextOptions>;
      getAllByLabelText: GetAllByQuery<TextMatch, ByLabelTextOptions>;
      queryByLabelText: QueryByQuery<TextMatch, ByLabelTextOptions>;
      queryAllByLabelText: QueryAllByQuery<TextMatch, ByLabelTextOptions>;
      findByLabelText: FindByQuery<TextMatch, ByLabelTextOptions>;
      findAllByLabelText: FindAllByQuery<TextMatch, ByLabelTextOptions>;
    };

    export const bindByLabelTextQueries = (
      instance: ReactTestInstance
    ): ByLabelTextQueries => ({
      getByLabelText: getBy(instance),
      getAllByLabelText: getAllBy(instance),
      queryByLabelText: queryBy(instance),
      queryAllByLabelText: queryAllBy(instance),
      findByLabelText: findBy(instance),
      findAllByLabelText: findAllBy(instance),
    });