From cc0d1c5b4092a1591c1beff36964b8f736a245a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Jastrze=CC=A8bski?= Date: Wed, 27 Dec 2023 14:04:31 +0100 Subject: [PATCH 1/3] docs: add jsdocs for jest matchers --- src/matchers/types.ts | 248 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 247 insertions(+), 1 deletion(-) diff --git a/src/matchers/types.ts b/src/matchers/types.ts index 78a85b886..168fcf4d9 100644 --- a/src/matchers/types.ts +++ b/src/matchers/types.ts @@ -6,26 +6,272 @@ import { Style } from './to-have-style'; export interface JestNativeMatchers { /** - * Assert whether an element is present in the element tree or not. + * Assert whether a host element is present in the element tree (screen) or not. + * + * @see + * [Jest Matchers docs](https://callstack.github.io/react-native-testing-library/docs/jest-matchers#tobeonthescreen) + * + * @example + * Hello + * + * expect(getByText('Hello')).toBeOnTheScreen() + * expect(queryByText('Other')).not.toBeOnTheScreen() */ toBeOnTheScreen(): R; + /** + * Assert whether a host element is checked based on accessibility props. + * + * @see + * [Jest Matchers docs](https://callstack.github.io/react-native-testing-library/docs/jest-matchers#tobechecked) + * + * @see {@link toBePartiallyChecked} for a related matcher. + * + * @example + * + * + * expect(getByRole('checkbox', { name: "Enable" })).toBeChecked() + */ toBeChecked(): R; + + /** + * Assert whether a host element is collapsed based on accessibility props. + * + * @see + * [Jest Matchers docs](https://callstack.github.io/react-native-testing-library/docs/jest-matchers#tobeexpanded) + * + * @see {@link toBeExpanded} for an inverse matcher. + * + * @example + * + * + * expect(getByTestId('details').toBeCollapsed() + */ toBeCollapsed(): R; + + /** + * Assert whether a host element is disabled based on accessibility props. + * + * This matcher will check ancestor elements for their disabled state as well. + * + * @see + * [Jest Matchers docs](https://callstack.github.io/react-native-testing-library/docs/jest-matchers#tobeenabled) + * + * @see {@link toBeEnabled} for an inverse matcher. + * + * @example + * + * + * expect(getByRole('button').toBeDisabled() + * + */ toBeDisabled(): R; + + /** + * Assert whether a host element is busy based on accessibility props. + * + * @see + * [Jest Matchers docs](https://callstack.github.io/react-native-testing-library/docs/jest-matchers#tobebusy) + * + * @example + * + * + * expect(getByTestId('loader')).toBeBusy() + */ toBeBusy(): R; + + /** + * Assert whether a host element has no host children or text content. + * + * @see + * [Jest Matchers docs](https://callstack.github.io/react-native-testing-library/docs/jest-matchers#tobeemptyelement) + * + * @example + * + * + * + * + * expect(getByTestId('empty')).toBeEmptyElement() + * expect(getByTestId('not-mepty')).not.toBeEmptyElement() + */ toBeEmptyElement(): R; + + /** + * Assert whether a host element is enabled based on accessibility props. + * + * This matcher will check ancestor elements for their enabled state as well. + * + * @see + * [Jest Matchers docs](https://callstack.github.io/react-native-testing-library/docs/jest-matchers#tobeenabled) + * + * @see {@link toBeDisabled} for inverse matcher. + * + * @example + * + * + * expect(getByRole('button').toBeEnabled() + */ toBeEnabled(): R; + + /** + * Assert whether a host element is expanded based on accessibility props. + * + * @see + * [Jest Matchers docs](https://callstack.github.io/react-native-testing-library/docs/jest-matchers#tobeexpanded) + * + * @see {@link toBeCollapsed} for inverse matcher. + * + * @example + * + * + * expect(getByTestId('details').toBeExpanded() + */ toBeExpanded(): R; + + /** + * Assert whether a host element is partially checked based on accessibility props. + * + * @see + * [Jest Matchers docs](https://callstack.github.io/react-native-testing-library/docs/jest-matchers#tobechecked) + * + * @see {@link toBeChecked} for related matcher. + * + * @example + * + * + * expect(getByRole('checkbox', { name: "Enable" })).toBePartiallyChecked() + */ toBePartiallyChecked(): R; + + /** + * Assert whether a host element is selected based on accessibility props. + * + * @see + * [Jest Matchers docs](https://callstack.github.io/react-native-testing-library/docs/jest-matchers#tobeselected) + * + * @example + * + * + * expect(getByTestId('view')).toBeSelected() + */ toBeSelected(): R; + + /** + * Assert whether a host element is visible based on style and accessibility props. + * + * This matcher will check ancestor elements for their visibility as well. + * + * @see + * [Jest Matchers docs](https://callstack.github.io/react-native-testing-library/docs/jest-matchers#tobevisible) + * + * @example + * + * + * + * expect(getByTestId('visible')).toBeVisible() + * expect(getByTestId('not-visible')).not.toBeVisible() + */ toBeVisible(): R; + + /** + * Assert whether a host element contains another host element. + * + * @see + * [Jest Matchers docs](https://callstack.github.io/react-native-testing-library/docs/jest-matchers#tocontainelement) + * + * @example + * + * + * + * + * expect(getByTestId('outer')).toContainElement(getByTestId('inner')); + */ toContainElement(element: ReactTestInstance | null): R; + + /** + * Assert whether a host element has a given accessbility value. + * + * @see + * [Jest Matchers docs](https://callstack.github.io/react-native-testing-library/docs/jest-matchers#tohaveaccessibilityvalue) + * + * + * @example + * + * + * expect(getByTestId('view')).toHaveAccessibilityValue({ text: '33%' }); + */ toHaveAccessibilityValue(expectedValue: AccessibilityValueMatcher): R; + + /** + * Assert whether a host element has a given accessibile name based on the accessibility label or text content. + * + * @see + * [Jest Matchers docs](https://callstack.github.io/react-native-testing-library/docs/jest-matchers#tohaveaccessiblename) + * + * @example + * + * + * expect(getByTestId('view')).toHaveAccessibleName('Hello'); + */ toHaveAccessibleName(expectedName?: TextMatch, options?: TextMatchOptions): R; + + /** + * Assert whether a host `TextInput` element has a given display value based on `value` and `defaultValue` props. + * + * @see + * [Jest Matchers docs](https://callstack.github.io/react-native-testing-library/docs/jest-matchers#tohavedisplayvalue) + * + * @example + * + * + * expect(getByTestId('input')).toHaveDisplayValue('Hello'); + */ toHaveDisplayValue(expectedValue: TextMatch, options?: TextMatchOptions): R; + + /** + * Assert whether a host element has a given prop. + * + * @see + * [Jest Matchers docs](https://callstack.github.io/react-native-testing-library/docs/jest-matchers#tohaveprop) + * + * @example + * + * + * expect(getByTestId('text')).toHaveProp('numberOfLines'); + * expect(getByTestId('text')).toHaveProp('numberOfLines', 1); + */ toHaveProp(name: string, expectedValue?: unknown): R; + + /** + * Assert whether a host element has a given style. + * + * @see + * [Jest Matchers docs](https://callstack.github.io/react-native-testing-library/docs/jest-matchers#tohavestyle) + * + * @example + * + * + * expect(getByTestId('view')).toHaveStyle({ width: '100%' }); + * expect(getByTestId('view')).not.toHaveStyle({ width: '50%' }); + */ toHaveStyle(style: StyleProp