33 lines
1.2 KiB
TypeScript

import { queryHelpers, buildQueries } from '@testing-library/react';
import type { DataDateString } from 'shared/types/date';
import type { GetErrorFunction } from '@testing-library/dom/types/query-helpers';
import type { Matcher, MatcherOptions } from '@testing-library/react';
const queryAllByDataDate = (
container: HTMLElement,
id: Matcher,
options?: MatcherOptions | undefined,
) => queryHelpers.queryAllByAttribute('data-date', container, id, options);
const getMultipleError: GetErrorFunction<[id: DataDateString, options?: MatcherOptions | undefined]> = (_, dataDateValue) => `Found multiple elements with the data-date attribute of: ${dataDateValue}`;
const getMissingError: GetErrorFunction<[id: DataDateString, options?: MatcherOptions | undefined]> = (_, dataDateValue: string) => `Unable to find an element with the data-date attribute of: ${dataDateValue}`;
const [
queryByDataDate,
getAllByDataDate,
getByDataDate,
findAllByDataDate,
findByDataDate,
] = buildQueries(queryAllByDataDate, getMultipleError, getMissingError);
export {
queryByDataDate,
queryAllByDataDate,
getByDataDate,
getAllByDataDate,
findAllByDataDate,
findByDataDate,
};