From 77c9cb03bff01b44a8579b10acf8359b36eb74e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Jastrze=CC=A8bski?= Date: Tue, 21 Apr 2026 12:50:39 +0200 Subject: [PATCH 1/5] automatic rename --- .../references/api-reference-v14.md | 44 ++++++------- src/fire-event.ts | 22 +++---- src/helpers/accessibility.ts | 32 +++++----- src/helpers/find-all.ts | 10 +-- src/helpers/format-element.ts | 6 +- src/helpers/host-component-names.ts | 14 ++-- .../matchers/match-accessibility-state.ts | 4 +- .../matchers/match-accessibility-value.ts | 4 +- src/helpers/matchers/match-label-text.ts | 4 +- src/helpers/matchers/match-text-content.ts | 4 +- src/helpers/pointer-events.ts | 4 +- src/helpers/text-content.ts | 4 +- src/helpers/text-input.ts | 6 +- .../to-have-accessible-name.test.tsx | 6 +- src/matchers/to-be-busy.ts | 4 +- src/matchers/to-be-checked.ts | 6 +- src/matchers/to-be-disabled.ts | 8 +-- src/matchers/to-be-empty-element.ts | 4 +- src/matchers/to-be-expanded.ts | 6 +- src/matchers/to-be-on-the-screen.ts | 4 +- src/matchers/to-be-partially-checked.ts | 6 +- src/matchers/to-be-selected.ts | 4 +- src/matchers/to-be-visible.ts | 12 ++-- src/matchers/to-contain-element.ts | 8 +-- src/matchers/to-have-accessibility-value.ts | 4 +- src/matchers/to-have-accessible-name.ts | 4 +- src/matchers/to-have-display-value.ts | 4 +- src/matchers/to-have-prop.ts | 4 +- src/matchers/to-have-style.ts | 4 +- src/matchers/to-have-text-content.ts | 4 +- src/matchers/types.ts | 4 +- src/matchers/utils.ts | 8 +-- src/native-state.ts | 6 +- src/queries/display-value.ts | 8 +-- src/queries/hint-text.ts | 8 +-- src/queries/label-text.ts | 6 +- src/queries/make-queries.ts | 26 ++++---- src/queries/placeholder-text.ts | 8 +-- src/queries/role.ts | 12 ++-- src/queries/test-id.ts | 8 +-- src/queries/text.ts | 6 +- src/render.tsx | 6 +- src/screen.ts | 6 +- src/user-event/clear.ts | 4 +- src/user-event/index.ts | 14 ++-- src/user-event/paste.ts | 4 +- src/user-event/press/press.ts | 18 +++--- src/user-event/scroll/scroll-to.ts | 10 +-- src/user-event/setup/setup.ts | 14 ++-- src/user-event/type/type.ts | 8 +-- src/user-event/utils/dispatch-event.ts | 4 +- src/within.ts | 4 +- .../docs/14.x/cookbook/basics/async-events.md | 2 +- .../docs/14.x/docs/advanced/testing-env.mdx | 12 ++-- .../docs/14.x/docs/api/events/fire-event.mdx | 8 +-- .../docs/14.x/docs/api/events/user-event.mdx | 12 ++-- website/docs/14.x/docs/api/jest-matchers.mdx | 2 +- .../docs/14.x/docs/api/misc/accessibility.mdx | 2 +- website/docs/14.x/docs/api/misc/other.mdx | 2 +- website/docs/14.x/docs/api/queries.mdx | 64 +++++++++---------- website/docs/14.x/docs/api/render.mdx | 2 +- website/docs/14.x/docs/api/screen.mdx | 8 +-- .../docs/14.x/docs/guides/how-to-query.mdx | 16 ++--- .../docs/14.x/docs/start/migration-v14.mdx | 4 +- 64 files changed, 288 insertions(+), 288 deletions(-) diff --git a/skills/react-native-testing/references/api-reference-v14.md b/skills/react-native-testing/references/api-reference-v14.md index 55e3351c6..6eb28e55c 100644 --- a/skills/react-native-testing/references/api-reference-v14.md +++ b/skills/react-native-testing/references/api-reference-v14.md @@ -3,7 +3,7 @@ Complete API reference for `@testing-library/react-native` v14.x (React 19+). **Test renderer:** `test-renderer` (not `react-test-renderer`) -**Element type:** `HostElement` (not `ReactTestInstance`) +**Element type:** `TestInstance` (not `ReactTestInstance`) ## Table of Contents @@ -106,8 +106,8 @@ let screen: { unmount(): Promise; // async debug(options?: { message?: string; mapProps?: MapPropsFunction }): void; toJSON(): RendererJSON | null; - container: HostElement; // safe root host element - root: HostElement; // root host element + container: TestInstance; // safe root host element + root: TestInstance; // root host element }; ``` @@ -132,14 +132,14 @@ Each query = **variant** + **predicate** (e.g., `getByRole` = `getBy` + `ByRole` ### Query Variants -| Variant | Assertion | Return Type | Async | -| ------------- | ------------------ | ------------------------------------ | ----- | -| `getBy*` | Exactly one match | `HostElement` (throws if 0 or >1) | No | -| `getAllBy*` | At least one match | `HostElement[]` (throws if 0) | No | -| `queryBy*` | Zero or one match | `HostElement \| null` (throws if >1) | No | -| `queryAllBy*` | No assertion | `HostElement[]` (empty if 0) | No | -| `findBy*` | Exactly one match | `Promise` | Yes | -| `findAllBy*` | At least one match | `Promise` | Yes | +| Variant | Assertion | Return Type | Async | +| ------------- | ------------------ | ------------------------------------- | ----- | +| `getBy*` | Exactly one match | `TestInstance` (throws if 0 or >1) | No | +| `getAllBy*` | At least one match | `TestInstance[]` (throws if 0) | No | +| `queryBy*` | Zero or one match | `TestInstance \| null` (throws if >1) | No | +| `queryAllBy*` | No assertion | `TestInstance[]` (empty if 0) | No | +| `findBy*` | Exactly one match | `Promise` | Yes | +| `findAllBy*` | At least one match | `Promise` | Yes | `findBy*` / `findAllBy*` accept optional `waitForOptions: { timeout?, interval?, onTimeout? }`. @@ -157,7 +157,7 @@ getByRole(role: TextMatch, options?: { expanded?: boolean; value?: { min?: number; max?: number; now?: number; text?: TextMatch }; includeHiddenElements?: boolean; -}): HostElement; +}): TestInstance; ``` Matches elements by `role` or `accessibilityRole`. Element must be an accessibility element: @@ -177,7 +177,7 @@ screen.getByRole('slider', { value: { now: 50, min: 0, max: 100 } }); #### `*ByLabelText` ```ts -getByLabelText(text: TextMatch, options?: { exact?: boolean; normalizer?: Function; includeHiddenElements?: boolean }): HostElement; +getByLabelText(text: TextMatch, options?: { exact?: boolean; normalizer?: Function; includeHiddenElements?: boolean }): TestInstance; ``` Matches by `aria-label`/`accessibilityLabel` or text content of element referenced by `aria-labelledby`/`accessibilityLabelledBy`. @@ -185,7 +185,7 @@ Matches by `aria-label`/`accessibilityLabel` or text content of element referenc #### `*ByPlaceholderText` ```ts -getByPlaceholderText(text: TextMatch, options?: { exact?: boolean; normalizer?: Function; includeHiddenElements?: boolean }): HostElement; +getByPlaceholderText(text: TextMatch, options?: { exact?: boolean; normalizer?: Function; includeHiddenElements?: boolean }): TestInstance; ``` Matches `TextInput` by `placeholder` prop. @@ -193,7 +193,7 @@ Matches `TextInput` by `placeholder` prop. #### `*ByText` ```ts -getByText(text: TextMatch, options?: { exact?: boolean; normalizer?: Function; includeHiddenElements?: boolean }): HostElement; +getByText(text: TextMatch, options?: { exact?: boolean; normalizer?: Function; includeHiddenElements?: boolean }): TestInstance; ``` Matches by text content. Joins `` siblings to find matches (like RN runtime). @@ -201,7 +201,7 @@ Matches by text content. Joins `` siblings to find matches (like RN runtim #### `*ByDisplayValue` ```ts -getByDisplayValue(value: TextMatch, options?: { exact?: boolean; normalizer?: Function; includeHiddenElements?: boolean }): HostElement; +getByDisplayValue(value: TextMatch, options?: { exact?: boolean; normalizer?: Function; includeHiddenElements?: boolean }): TestInstance; ``` Matches `TextInput` by current display value. @@ -209,7 +209,7 @@ Matches `TextInput` by current display value. #### `*ByHintText` ```ts -getByHintText(hint: TextMatch, options?: { exact?: boolean; normalizer?: Function; includeHiddenElements?: boolean }): HostElement; +getByHintText(hint: TextMatch, options?: { exact?: boolean; normalizer?: Function; includeHiddenElements?: boolean }): TestInstance; ``` Matches by `accessibilityHint` prop. Also available as `getByA11yHint` / `getByAccessibilityHint`. @@ -217,7 +217,7 @@ Matches by `accessibilityHint` prop. Also available as `getByA11yHint` / `getByA #### `*ByTestId` (last resort) ```ts -getByTestId(testId: TextMatch, options?: { exact?: boolean; normalizer?: Function; includeHiddenElements?: boolean }): HostElement; +getByTestId(testId: TextMatch, options?: { exact?: boolean; normalizer?: Function; includeHiddenElements?: boolean }): TestInstance; ``` Matches by `testID` prop. Use only when other queries don't work. @@ -326,7 +326,7 @@ Use when `userEvent` doesn't support the event or when triggering events on comp ```ts async function fireEvent( - element: HostElement, + element: TestInstance, eventName: string, ...data: unknown[] ): Promise; @@ -361,7 +361,7 @@ Available automatically with any `@testing-library/react-native` import. No setu | Matcher | Signature | Description | | --------------------- | ------------------------------------------------------------- | --------------------------- | | `toHaveTextContent()` | `(text: string \| RegExp, options?: { exact?, normalizer? })` | Text content match | -| `toContainElement()` | `(element: HostElement \| null)` | Contains child element | +| `toContainElement()` | `(element: TestInstance \| null)` | Contains child element | | `toBeEmptyElement()` | — | No children or text content | ### Element State @@ -430,7 +430,7 @@ Waits until the queried element is removed. Element must be initially present. ### `within` ```ts -function within(element: HostElement): Queries; +function within(element: TestInstance): Queries; ``` Scoped queries on a subtree. Useful for querying within a single `FlatList` item or a specific screen. @@ -533,7 +533,7 @@ Note: `concurrentRoot` option is removed (always on). `unstable_validateStringsR ### `isHiddenFromAccessibility` ```ts -function isHiddenFromAccessibility(element: HostElement | null): boolean; +function isHiddenFromAccessibility(element: TestInstance | null): boolean; ``` Also available as `isInaccessible()` alias. diff --git a/src/fire-event.ts b/src/fire-event.ts index e6f733642..b9e72e4ee 100644 --- a/src/fire-event.ts +++ b/src/fire-event.ts @@ -5,7 +5,7 @@ import type { TextProps, ViewProps, } from 'react-native'; -import type { Fiber, HostElement } from 'test-renderer'; +import type { Fiber, TestInstance } from 'test-renderer'; import { act } from './act'; import { buildScrollEvent, buildTouchEvent } from './event-builder'; @@ -18,7 +18,7 @@ import { isEditableTextInput } from './helpers/text-input'; import { nativeState } from './native-state'; import type { Point, StringWithAutocomplete } from './types'; -function isTouchResponder(element: HostElement) { +function isTouchResponder(element: TestInstance) { return Boolean(element.props.onStartShouldSetResponder) || isHostTextInput(element); } @@ -46,9 +46,9 @@ const textInputEventsIgnoringEditableProp = new Set([ ]); function isEventEnabled( - element: HostElement, + element: TestInstance, eventName: string, - nearestTouchResponder?: HostElement, + nearestTouchResponder?: TestInstance, ) { if (nearestTouchResponder != null && isHostTextInput(nearestTouchResponder)) { return ( @@ -71,9 +71,9 @@ function isEventEnabled( } function findEventHandler( - element: HostElement, + element: TestInstance, eventName: string, - nearestTouchResponder?: HostElement, + nearestTouchResponder?: TestInstance, ): EventHandler | null { const touchResponder = isTouchResponder(element) ? element : nearestTouchResponder; @@ -123,7 +123,7 @@ type EventName = StringWithAutocomplete< | EventNameExtractor >; -async function fireEvent(element: HostElement, eventName: EventName, ...data: unknown[]) { +async function fireEvent(element: TestInstance, eventName: EventName, ...data: unknown[]) { if (!isElementMounted(element)) { return; } @@ -145,10 +145,10 @@ async function fireEvent(element: HostElement, eventName: EventName, ...data: un type EventProps = Record; -fireEvent.changeText = async (element: HostElement, text: string) => +fireEvent.changeText = async (element: TestInstance, text: string) => await fireEvent(element, 'changeText', text); -fireEvent.press = async (element: HostElement, eventProps?: EventProps) => { +fireEvent.press = async (element: TestInstance, eventProps?: EventProps) => { const event = buildTouchEvent(); if (eventProps) { mergeEventProps(event, eventProps); @@ -157,7 +157,7 @@ fireEvent.press = async (element: HostElement, eventProps?: EventProps) => { await fireEvent(element, 'press', event); }; -fireEvent.scroll = async (element: HostElement, eventProps?: EventProps) => { +fireEvent.scroll = async (element: TestInstance, eventProps?: EventProps) => { const event = buildScrollEvent(); if (eventProps) { mergeEventProps(event, eventProps); @@ -176,7 +176,7 @@ const scrollEventNames = new Set([ 'momentumScrollEnd', ]); -function setNativeStateIfNeeded(element: HostElement, eventName: string, value: unknown) { +function setNativeStateIfNeeded(element: TestInstance, eventName: string, value: unknown) { if (eventName === 'changeText' && typeof value === 'string' && isEditableTextInput(element)) { nativeState.valueForElement.set(element, value); } diff --git a/src/helpers/accessibility.ts b/src/helpers/accessibility.ts index 14fcea554..adb8498ce 100644 --- a/src/helpers/accessibility.ts +++ b/src/helpers/accessibility.ts @@ -1,6 +1,6 @@ import type { AccessibilityRole, AccessibilityState, AccessibilityValue, Role } from 'react-native'; import { StyleSheet } from 'react-native'; -import type { HostElement } from 'test-renderer'; +import type { TestInstance } from 'test-renderer'; import { getContainerElement, getInstanceSiblings, isTestInstance } from './component-tree'; import { findAll } from './find-all'; @@ -9,7 +9,7 @@ import { getTextContent } from './text-content'; import { isEditableTextInput } from './text-input'; type IsInaccessibleOptions = { - cache?: WeakMap; + cache?: WeakMap; }; export const accessibilityStateKeys: (keyof AccessibilityState)[] = [ @@ -23,14 +23,14 @@ export const accessibilityStateKeys: (keyof AccessibilityState)[] = [ export const accessibilityValueKeys: (keyof AccessibilityValue)[] = ['min', 'max', 'now', 'text']; export function isHiddenFromAccessibility( - element: HostElement | null, + element: TestInstance | null, { cache }: IsInaccessibleOptions = {}, ): boolean { if (element == null) { return true; } - let current: HostElement | null = element; + let current: TestInstance | null = element; while (current) { let isCurrentSubtreeInaccessible = cache?.get(current); @@ -52,7 +52,7 @@ export function isHiddenFromAccessibility( /** RTL-compatibility alias for `isHiddenFromAccessibility` */ export const isInaccessible = isHiddenFromAccessibility; -function isSubtreeInaccessible(element: HostElement): boolean { +function isSubtreeInaccessible(element: TestInstance): boolean { // See: https://reactnative.dev/docs/accessibility#aria-hidden if (element.props['aria-hidden']) { return true; @@ -84,7 +84,7 @@ function isSubtreeInaccessible(element: HostElement): boolean { return false; } -export function isAccessibilityElement(element: HostElement | null): boolean { +export function isAccessibilityElement(element: TestInstance | null): boolean { if (element == null) { return false; } @@ -114,7 +114,7 @@ export function isAccessibilityElement(element: HostElement | null): boolean { * @param element * @returns */ -export function getRole(element: HostElement): Role | AccessibilityRole { +export function getRole(element: TestInstance): Role | AccessibilityRole { const explicitRole = element.props.role ?? element.props.accessibilityRole; if (explicitRole) { return normalizeRole(explicitRole); @@ -145,11 +145,11 @@ export function normalizeRole(role: string): Role | AccessibilityRole { return role as Role | AccessibilityRole; } -export function computeAriaModal(element: HostElement): boolean | undefined { +export function computeAriaModal(element: TestInstance): boolean | undefined { return element.props['aria-modal'] ?? element.props.accessibilityViewIsModal; } -export function computeAriaLabel(element: HostElement): string | undefined { +export function computeAriaLabel(element: TestInstance): string | undefined { const labelElementId = element.props['aria-labelledby'] ?? element.props.accessibilityLabelledBy; if (labelElementId) { const container = getContainerElement(element); @@ -177,12 +177,12 @@ export function computeAriaLabel(element: HostElement): string | undefined { } // See: https://github.com/callstack/react-native-testing-library/wiki/Accessibility:-State#busy-state -export function computeAriaBusy({ props }: HostElement): boolean { +export function computeAriaBusy({ props }: TestInstance): boolean { return props['aria-busy'] ?? props.accessibilityState?.busy ?? false; } // See: https://github.com/callstack/react-native-testing-library/wiki/Accessibility:-State#checked-state -export function computeAriaChecked(element: HostElement): AccessibilityState['checked'] { +export function computeAriaChecked(element: TestInstance): AccessibilityState['checked'] { const { props } = element; if (isHostSwitch(element)) { @@ -198,7 +198,7 @@ export function computeAriaChecked(element: HostElement): AccessibilityState['ch } // See: https://github.com/callstack/react-native-testing-library/wiki/Accessibility:-State#disabled-state -export function computeAriaDisabled(element: HostElement): boolean { +export function computeAriaDisabled(element: TestInstance): boolean { if (isHostTextInput(element) && !isEditableTextInput(element)) { return true; } @@ -213,16 +213,16 @@ export function computeAriaDisabled(element: HostElement): boolean { } // See: https://github.com/callstack/react-native-testing-library/wiki/Accessibility:-State#expanded-state -export function computeAriaExpanded({ props }: HostElement): boolean | undefined { +export function computeAriaExpanded({ props }: TestInstance): boolean | undefined { return props['aria-expanded'] ?? props.accessibilityState?.expanded; } // See: https://github.com/callstack/react-native-testing-library/wiki/Accessibility:-State#selected-state -export function computeAriaSelected({ props }: HostElement): boolean { +export function computeAriaSelected({ props }: TestInstance): boolean { return props['aria-selected'] ?? props.accessibilityState?.selected ?? false; } -export function computeAriaValue(element: HostElement): AccessibilityValue { +export function computeAriaValue(element: TestInstance): AccessibilityValue { const { accessibilityValue, 'aria-valuemax': ariaValueMax, @@ -244,7 +244,7 @@ type ComputeAccessibleNameOptions = { }; export function computeAccessibleName( - element: HostElement, + element: TestInstance, options?: ComputeAccessibleNameOptions, ): string | undefined { const label = computeAriaLabel(element); diff --git a/src/helpers/find-all.ts b/src/helpers/find-all.ts index 00389e159..0d342a15d 100644 --- a/src/helpers/find-all.ts +++ b/src/helpers/find-all.ts @@ -1,4 +1,4 @@ -import type { HostElement } from 'test-renderer'; +import type { TestInstance } from 'test-renderer'; import { getConfig } from '../config'; import { isHiddenFromAccessibility } from './accessibility'; @@ -15,10 +15,10 @@ interface FindAllOptions { } export function findAll( - root: HostElement, - predicate: (element: HostElement) => boolean, + root: TestInstance, + predicate: (element: TestInstance) => boolean, options: FindAllOptions = {}, -): HostElement[] { +): TestInstance[] { const { matchDeepestOnly } = options; const results = root.queryAll(predicate, { matchDeepestOnly }); @@ -29,6 +29,6 @@ export function findAll( return results; } - const cache = new WeakMap(); + const cache = new WeakMap(); return results.filter((element) => !isHiddenFromAccessibility(element, { cache })); } diff --git a/src/helpers/format-element.ts b/src/helpers/format-element.ts index 4dd33e4a3..43a538f47 100644 --- a/src/helpers/format-element.ts +++ b/src/helpers/format-element.ts @@ -1,6 +1,6 @@ import type { NewPlugin } from 'pretty-format'; import prettyFormat, { plugins } from 'pretty-format'; -import type { HostElement, JsonNode } from 'test-renderer'; +import type { JsonNode, TestInstance } from 'test-renderer'; import type { MapPropsFunction } from './map-props'; import { defaultMapProps } from './map-props'; @@ -22,7 +22,7 @@ export type FormatElementOptions = { * @param element Element to format. */ export function formatElement( - element: HostElement | null, + element: TestInstance | null, { compact, highlight = true, mapProps = defaultMapProps }: FormatElementOptions = {}, ) { if (element == null) { @@ -52,7 +52,7 @@ export function formatElement( ); } -export function formatElementList(elements: HostElement[], options?: FormatElementOptions) { +export function formatElementList(elements: TestInstance[], options?: FormatElementOptions) { if (elements.length === 0) { return '(no elements)'; } diff --git a/src/helpers/host-component-names.ts b/src/helpers/host-component-names.ts index 4a25eae7d..56ab17eea 100644 --- a/src/helpers/host-component-names.ts +++ b/src/helpers/host-component-names.ts @@ -1,4 +1,4 @@ -import type { HostElement } from 'test-renderer'; +import type { TestInstance } from 'test-renderer'; export const HOST_TEXT_NAMES = ['Text', 'RCTText']; const HOST_TEXT_INPUT_NAMES = ['TextInput']; @@ -11,7 +11,7 @@ const HOST_MODAL_NAMES = ['Modal']; * Checks if the given element is a host Text element. * @param element The element to check. */ -export function isHostText(element: HostElement | null) { +export function isHostText(element: TestInstance | null) { return typeof element?.type === 'string' && HOST_TEXT_NAMES.includes(element.type); } @@ -19,7 +19,7 @@ export function isHostText(element: HostElement | null) { * Checks if the given element is a host TextInput element. * @param element The element to check. */ -export function isHostTextInput(element: HostElement | null) { +export function isHostTextInput(element: TestInstance | null) { return typeof element?.type === 'string' && HOST_TEXT_INPUT_NAMES.includes(element.type); } @@ -27,7 +27,7 @@ export function isHostTextInput(element: HostElement | null) { * Checks if the given element is a host Image element. * @param element The element to check. */ -export function isHostImage(element: HostElement | null) { +export function isHostImage(element: TestInstance | null) { return typeof element?.type === 'string' && HOST_IMAGE_NAMES.includes(element.type); } @@ -35,7 +35,7 @@ export function isHostImage(element: HostElement | null) { * Checks if the given element is a host Switch element. * @param element The element to check. */ -export function isHostSwitch(element: HostElement | null) { +export function isHostSwitch(element: TestInstance | null) { return typeof element?.type === 'string' && HOST_SWITCH_NAMES.includes(element.type); } @@ -43,7 +43,7 @@ export function isHostSwitch(element: HostElement | null) { * Checks if the given element is a host ScrollView element. * @param element The element to check. */ -export function isHostScrollView(element: HostElement | null) { +export function isHostScrollView(element: TestInstance | null) { return typeof element?.type === 'string' && HOST_SCROLL_VIEW_NAMES.includes(element.type); } @@ -51,6 +51,6 @@ export function isHostScrollView(element: HostElement | null) { * Checks if the given element is a host Modal element. * @param element The element to check. */ -export function isHostModal(element: HostElement | null) { +export function isHostModal(element: TestInstance | null) { return typeof element?.type === 'string' && HOST_MODAL_NAMES.includes(element.type); } diff --git a/src/helpers/matchers/match-accessibility-state.ts b/src/helpers/matchers/match-accessibility-state.ts index 896cdb1ea..b48551000 100644 --- a/src/helpers/matchers/match-accessibility-state.ts +++ b/src/helpers/matchers/match-accessibility-state.ts @@ -1,4 +1,4 @@ -import type { HostElement } from 'test-renderer'; +import type { TestInstance } from 'test-renderer'; import { computeAriaBusy, @@ -20,7 +20,7 @@ export interface AccessibilityStateMatcher { expanded?: boolean; } -export function matchAccessibilityState(node: HostElement, matcher: AccessibilityStateMatcher) { +export function matchAccessibilityState(node: TestInstance, matcher: AccessibilityStateMatcher) { if (matcher.busy !== undefined && matcher.busy !== computeAriaBusy(node)) { return false; } diff --git a/src/helpers/matchers/match-accessibility-value.ts b/src/helpers/matchers/match-accessibility-value.ts index 24141f205..edfe3b748 100644 --- a/src/helpers/matchers/match-accessibility-value.ts +++ b/src/helpers/matchers/match-accessibility-value.ts @@ -1,4 +1,4 @@ -import type { HostElement } from 'test-renderer'; +import type { TestInstance } from 'test-renderer'; import type { TextMatch } from '../../matches'; import { computeAriaValue } from '../accessibility'; @@ -12,7 +12,7 @@ export interface AccessibilityValueMatcher { } export function matchAccessibilityValue( - node: HostElement, + node: TestInstance, matcher: AccessibilityValueMatcher, ): boolean { const value = computeAriaValue(node); diff --git a/src/helpers/matchers/match-label-text.ts b/src/helpers/matchers/match-label-text.ts index 22070d12a..a19b0fd08 100644 --- a/src/helpers/matchers/match-label-text.ts +++ b/src/helpers/matchers/match-label-text.ts @@ -1,11 +1,11 @@ -import type { HostElement } from 'test-renderer'; +import type { TestInstance } from 'test-renderer'; import type { TextMatch, TextMatchOptions } from '../../matches'; import { matches } from '../../matches'; import { computeAriaLabel } from '../accessibility'; export function matchAccessibilityLabel( - element: HostElement, + element: TestInstance, expectedLabel: TextMatch, options?: TextMatchOptions, ) { diff --git a/src/helpers/matchers/match-text-content.ts b/src/helpers/matchers/match-text-content.ts index 8cc9d759f..bfccdcb60 100644 --- a/src/helpers/matchers/match-text-content.ts +++ b/src/helpers/matchers/match-text-content.ts @@ -1,4 +1,4 @@ -import type { HostElement } from 'test-renderer'; +import type { TestInstance } from 'test-renderer'; import type { TextMatch, TextMatchOptions } from '../../matches'; import { matches } from '../../matches'; @@ -12,7 +12,7 @@ import { getTextContent } from '../text-content'; * @returns - Whether the node's text content matches the given string or regex. */ export function matchTextContent( - node: HostElement, + node: TestInstance, text: TextMatch, options: TextMatchOptions = {}, ) { diff --git a/src/helpers/pointer-events.ts b/src/helpers/pointer-events.ts index e7114c15a..addf3aafb 100644 --- a/src/helpers/pointer-events.ts +++ b/src/helpers/pointer-events.ts @@ -1,5 +1,5 @@ import { StyleSheet } from 'react-native'; -import type { HostElement } from 'test-renderer'; +import type { TestInstance } from 'test-renderer'; /** * pointerEvents controls whether the View can be the target of touch events. @@ -8,7 +8,7 @@ import type { HostElement } from 'test-renderer'; * 'box-none': The View is never the target of touch events but its subviews can be * 'box-only': The view can be the target of touch events but its subviews cannot be * see the official react native doc https://reactnative.dev/docs/view#pointerevents */ -export const isPointerEventEnabled = (element: HostElement, isParent?: boolean): boolean => { +export const isPointerEventEnabled = (element: TestInstance, isParent?: boolean): boolean => { // Check both props.pointerEvents and props.style.pointerEvents const pointerEvents = element?.props.pointerEvents ?? StyleSheet.flatten(element?.props.style)?.pointerEvents; diff --git a/src/helpers/text-content.ts b/src/helpers/text-content.ts index aa6277935..6815e9b86 100644 --- a/src/helpers/text-content.ts +++ b/src/helpers/text-content.ts @@ -1,6 +1,6 @@ -import type { HostElement } from 'test-renderer'; +import type { TestInstance } from 'test-renderer'; -export function getTextContent(element: HostElement | string | null): string { +export function getTextContent(element: TestInstance | string | null): string { if (!element) { return ''; } diff --git a/src/helpers/text-input.ts b/src/helpers/text-input.ts index e33b78d89..b0c2b890f 100644 --- a/src/helpers/text-input.ts +++ b/src/helpers/text-input.ts @@ -1,13 +1,13 @@ -import type { HostElement } from 'test-renderer'; +import type { TestInstance } from 'test-renderer'; import { nativeState } from '../native-state'; import { isHostTextInput } from './host-component-names'; -export function isEditableTextInput(element: HostElement) { +export function isEditableTextInput(element: TestInstance) { return isHostTextInput(element) && element.props.editable !== false; } -export function getTextInputValue(element: HostElement) { +export function getTextInputValue(element: TestInstance) { if (!isHostTextInput(element)) { throw new Error(`Element is not a "TextInput", but it has type "${element.type}".`); } diff --git a/src/matchers/__tests__/to-have-accessible-name.test.tsx b/src/matchers/__tests__/to-have-accessible-name.test.tsx index 406a8074c..2b703dc0f 100644 --- a/src/matchers/__tests__/to-have-accessible-name.test.tsx +++ b/src/matchers/__tests__/to-have-accessible-name.test.tsx @@ -119,14 +119,14 @@ test('toHaveAccessibleName() handles a view without name when called without exp }); it('toHaveAccessibleName() rejects non-host element', () => { - const nonElement = 'This is not a HostElement'; + const nonElement = 'This is not a TestInstance'; expect(() => expect(nonElement).toHaveAccessibleName()).toThrowErrorMatchingInlineSnapshot(` "expect(received).toHaveAccessibleName() received value must be a host element. Received has type: string - Received has value: "This is not a HostElement"" + Received has value: "This is not a TestInstance"" `); expect(() => expect(nonElement).not.toHaveAccessibleName()).toThrowErrorMatchingInlineSnapshot(` @@ -134,6 +134,6 @@ it('toHaveAccessibleName() rejects non-host element', () => { received value must be a host element. Received has type: string - Received has value: "This is not a HostElement"" + Received has value: "This is not a TestInstance"" `); }); diff --git a/src/matchers/to-be-busy.ts b/src/matchers/to-be-busy.ts index b86dab015..bcf4357eb 100644 --- a/src/matchers/to-be-busy.ts +++ b/src/matchers/to-be-busy.ts @@ -1,12 +1,12 @@ import { matcherHint } from 'jest-matcher-utils'; import redent from 'redent'; -import type { HostElement } from 'test-renderer'; +import type { TestInstance } from 'test-renderer'; import { computeAriaBusy } from '../helpers/accessibility'; import { formatElement } from '../helpers/format-element'; import { checkHostElement } from './utils'; -export function toBeBusy(this: jest.MatcherContext, element: HostElement) { +export function toBeBusy(this: jest.MatcherContext, element: TestInstance) { checkHostElement(element, toBeBusy, this); return { diff --git a/src/matchers/to-be-checked.ts b/src/matchers/to-be-checked.ts index 1d164ec70..8be7e0774 100644 --- a/src/matchers/to-be-checked.ts +++ b/src/matchers/to-be-checked.ts @@ -1,6 +1,6 @@ import { matcherHint } from 'jest-matcher-utils'; import redent from 'redent'; -import type { HostElement } from 'test-renderer'; +import type { TestInstance } from 'test-renderer'; import { computeAriaChecked, @@ -13,7 +13,7 @@ import { formatElement } from '../helpers/format-element'; import { isHostSwitch } from '../helpers/host-component-names'; import { checkHostElement } from './utils'; -export function toBeChecked(this: jest.MatcherContext, element: HostElement) { +export function toBeChecked(this: jest.MatcherContext, element: TestInstance) { checkHostElement(element, toBeChecked, this); if (!isHostSwitch(element) && !isSupportedAccessibilityElement(element)) { @@ -37,7 +37,7 @@ export function toBeChecked(this: jest.MatcherContext, element: HostElement) { }; } -function isSupportedAccessibilityElement(element: HostElement) { +function isSupportedAccessibilityElement(element: TestInstance) { if (!isAccessibilityElement(element)) { return false; } diff --git a/src/matchers/to-be-disabled.ts b/src/matchers/to-be-disabled.ts index 8ab740069..7c5e49e8c 100644 --- a/src/matchers/to-be-disabled.ts +++ b/src/matchers/to-be-disabled.ts @@ -1,12 +1,12 @@ import { matcherHint } from 'jest-matcher-utils'; import redent from 'redent'; -import type { HostElement } from 'test-renderer'; +import type { TestInstance } from 'test-renderer'; import { computeAriaDisabled } from '../helpers/accessibility'; import { formatElement } from '../helpers/format-element'; import { checkHostElement } from './utils'; -export function toBeDisabled(this: jest.MatcherContext, element: HostElement) { +export function toBeDisabled(this: jest.MatcherContext, element: TestInstance) { checkHostElement(element, toBeDisabled, this); const isDisabled = computeAriaDisabled(element) || isAncestorDisabled(element); @@ -25,7 +25,7 @@ export function toBeDisabled(this: jest.MatcherContext, element: HostElement) { }; } -export function toBeEnabled(this: jest.MatcherContext, element: HostElement) { +export function toBeEnabled(this: jest.MatcherContext, element: TestInstance) { checkHostElement(element, toBeEnabled, this); const isEnabled = !computeAriaDisabled(element) && !isAncestorDisabled(element); @@ -44,7 +44,7 @@ export function toBeEnabled(this: jest.MatcherContext, element: HostElement) { }; } -function isAncestorDisabled(element: HostElement): boolean { +function isAncestorDisabled(element: TestInstance): boolean { const parent = element.parent; if (parent == null) { return false; diff --git a/src/matchers/to-be-empty-element.ts b/src/matchers/to-be-empty-element.ts index a58c75914..a438f49d8 100644 --- a/src/matchers/to-be-empty-element.ts +++ b/src/matchers/to-be-empty-element.ts @@ -1,12 +1,12 @@ import { matcherHint, RECEIVED_COLOR } from 'jest-matcher-utils'; import redent from 'redent'; -import type { HostElement } from 'test-renderer'; +import type { TestInstance } from 'test-renderer'; import { isTestInstance } from '../helpers/component-tree'; import { formatElementList } from '../helpers/format-element'; import { checkHostElement } from './utils'; -export function toBeEmptyElement(this: jest.MatcherContext, element: HostElement) { +export function toBeEmptyElement(this: jest.MatcherContext, element: TestInstance) { checkHostElement(element, toBeEmptyElement, this); // TODO check diff --git a/src/matchers/to-be-expanded.ts b/src/matchers/to-be-expanded.ts index 66a72e09f..79d694a04 100644 --- a/src/matchers/to-be-expanded.ts +++ b/src/matchers/to-be-expanded.ts @@ -1,12 +1,12 @@ import { matcherHint } from 'jest-matcher-utils'; import redent from 'redent'; -import type { HostElement } from 'test-renderer'; +import type { TestInstance } from 'test-renderer'; import { computeAriaExpanded } from '../helpers/accessibility'; import { formatElement } from '../helpers/format-element'; import { checkHostElement } from './utils'; -export function toBeExpanded(this: jest.MatcherContext, element: HostElement) { +export function toBeExpanded(this: jest.MatcherContext, element: TestInstance) { checkHostElement(element, toBeExpanded, this); return { @@ -23,7 +23,7 @@ export function toBeExpanded(this: jest.MatcherContext, element: HostElement) { }; } -export function toBeCollapsed(this: jest.MatcherContext, element: HostElement) { +export function toBeCollapsed(this: jest.MatcherContext, element: TestInstance) { checkHostElement(element, toBeCollapsed, this); return { diff --git a/src/matchers/to-be-on-the-screen.ts b/src/matchers/to-be-on-the-screen.ts index 181a701e8..afc3fd7a8 100644 --- a/src/matchers/to-be-on-the-screen.ts +++ b/src/matchers/to-be-on-the-screen.ts @@ -1,13 +1,13 @@ import { matcherHint, RECEIVED_COLOR } from 'jest-matcher-utils'; import redent from 'redent'; -import type { HostElement } from 'test-renderer'; +import type { TestInstance } from 'test-renderer'; import { getContainerElement } from '../helpers/component-tree'; import { formatElement } from '../helpers/format-element'; import { screen } from '../screen'; import { checkHostElement } from './utils'; -export function toBeOnTheScreen(this: jest.MatcherContext, element: HostElement) { +export function toBeOnTheScreen(this: jest.MatcherContext, element: TestInstance) { if (element !== null || !this.isNot) { checkHostElement(element, toBeOnTheScreen, this); } diff --git a/src/matchers/to-be-partially-checked.ts b/src/matchers/to-be-partially-checked.ts index 68ed2f9f5..226fbbcf9 100644 --- a/src/matchers/to-be-partially-checked.ts +++ b/src/matchers/to-be-partially-checked.ts @@ -1,13 +1,13 @@ import { matcherHint } from 'jest-matcher-utils'; import redent from 'redent'; -import type { HostElement } from 'test-renderer'; +import type { TestInstance } from 'test-renderer'; import { computeAriaChecked, getRole, isAccessibilityElement } from '../helpers/accessibility'; import { ErrorWithStack } from '../helpers/errors'; import { formatElement } from '../helpers/format-element'; import { checkHostElement } from './utils'; -export function toBePartiallyChecked(this: jest.MatcherContext, element: HostElement) { +export function toBePartiallyChecked(this: jest.MatcherContext, element: TestInstance) { checkHostElement(element, toBePartiallyChecked, this); if (!hasValidAccessibilityRole(element)) { @@ -31,7 +31,7 @@ export function toBePartiallyChecked(this: jest.MatcherContext, element: HostEle }; } -function hasValidAccessibilityRole(element: HostElement) { +function hasValidAccessibilityRole(element: TestInstance) { const role = getRole(element); return isAccessibilityElement(element) && role === 'checkbox'; } diff --git a/src/matchers/to-be-selected.ts b/src/matchers/to-be-selected.ts index 71cf822a8..fb80459cc 100644 --- a/src/matchers/to-be-selected.ts +++ b/src/matchers/to-be-selected.ts @@ -1,12 +1,12 @@ import { matcherHint } from 'jest-matcher-utils'; import redent from 'redent'; -import type { HostElement } from 'test-renderer'; +import type { TestInstance } from 'test-renderer'; import { computeAriaSelected } from '../helpers/accessibility'; import { formatElement } from '../helpers/format-element'; import { checkHostElement } from './utils'; -export function toBeSelected(this: jest.MatcherContext, element: HostElement) { +export function toBeSelected(this: jest.MatcherContext, element: TestInstance) { checkHostElement(element, toBeSelected, this); return { diff --git a/src/matchers/to-be-visible.ts b/src/matchers/to-be-visible.ts index f5a08a109..1b8c6055b 100644 --- a/src/matchers/to-be-visible.ts +++ b/src/matchers/to-be-visible.ts @@ -1,14 +1,14 @@ import { StyleSheet } from 'react-native'; import { matcherHint } from 'jest-matcher-utils'; import redent from 'redent'; -import type { HostElement } from 'test-renderer'; +import type { TestInstance } from 'test-renderer'; import { isHiddenFromAccessibility } from '../helpers/accessibility'; import { formatElement } from '../helpers/format-element'; import { isHostModal } from '../helpers/host-component-names'; import { checkHostElement } from './utils'; -export function toBeVisible(this: jest.MatcherContext, element: HostElement) { +export function toBeVisible(this: jest.MatcherContext, element: TestInstance) { if (element !== null || !this.isNot) { checkHostElement(element, toBeVisible, this); } @@ -28,11 +28,11 @@ export function toBeVisible(this: jest.MatcherContext, element: HostElement) { } function isElementVisible( - element: HostElement, - accessibilityCache?: WeakMap, + element: TestInstance, + accessibilityCache?: WeakMap, ): boolean { // Use cache to speed up repeated searches by `isHiddenFromAccessibility`. - const cache = accessibilityCache ?? new WeakMap(); + const cache = accessibilityCache ?? new WeakMap(); if (isHiddenFromAccessibility(element, { cache })) { return false; } @@ -55,7 +55,7 @@ function isElementVisible( return isElementVisible(parent, cache); } -function isHiddenForStyles(element: HostElement) { +function isHiddenForStyles(element: TestInstance) { const flatStyle = StyleSheet.flatten(element.props.style); return flatStyle?.display === 'none' || flatStyle?.opacity === 0; } diff --git a/src/matchers/to-contain-element.ts b/src/matchers/to-contain-element.ts index 651934d52..f060a15be 100644 --- a/src/matchers/to-contain-element.ts +++ b/src/matchers/to-contain-element.ts @@ -1,14 +1,14 @@ import { matcherHint, RECEIVED_COLOR } from 'jest-matcher-utils'; import redent from 'redent'; -import type { HostElement } from 'test-renderer'; +import type { TestInstance } from 'test-renderer'; import { formatElement } from '../helpers/format-element'; import { checkHostElement } from './utils'; export function toContainElement( this: jest.MatcherContext, - container: HostElement, - element: HostElement | null, + container: TestInstance, + element: TestInstance | null, ) { checkHostElement(container, toContainElement, this); @@ -16,7 +16,7 @@ export function toContainElement( checkHostElement(element, toContainElement, this); } - let matches: HostElement[] = []; + let matches: TestInstance[] = []; if (element) { matches = container.queryAll((node) => node === element); } diff --git a/src/matchers/to-have-accessibility-value.ts b/src/matchers/to-have-accessibility-value.ts index 86c151266..bef1458a4 100644 --- a/src/matchers/to-have-accessibility-value.ts +++ b/src/matchers/to-have-accessibility-value.ts @@ -1,5 +1,5 @@ import { matcherHint, stringify } from 'jest-matcher-utils'; -import type { HostElement } from 'test-renderer'; +import type { TestInstance } from 'test-renderer'; import { computeAriaValue } from '../helpers/accessibility'; import type { AccessibilityValueMatcher } from '../helpers/matchers/match-accessibility-value'; @@ -9,7 +9,7 @@ import { checkHostElement, formatMessage } from './utils'; export function toHaveAccessibilityValue( this: jest.MatcherContext, - element: HostElement, + element: TestInstance, expectedValue: AccessibilityValueMatcher, ) { checkHostElement(element, toHaveAccessibilityValue, this); diff --git a/src/matchers/to-have-accessible-name.ts b/src/matchers/to-have-accessible-name.ts index e88adf919..7d309cae0 100644 --- a/src/matchers/to-have-accessible-name.ts +++ b/src/matchers/to-have-accessible-name.ts @@ -1,5 +1,5 @@ import { matcherHint } from 'jest-matcher-utils'; -import type { HostElement } from 'test-renderer'; +import type { TestInstance } from 'test-renderer'; import { computeAccessibleName } from '../helpers/accessibility'; import type { TextMatch, TextMatchOptions } from '../matches'; @@ -8,7 +8,7 @@ import { checkHostElement, formatMessage } from './utils'; export function toHaveAccessibleName( this: jest.MatcherContext, - element: HostElement, + element: TestInstance, expectedName?: TextMatch, options?: TextMatchOptions, ) { diff --git a/src/matchers/to-have-display-value.ts b/src/matchers/to-have-display-value.ts index 76d9eab05..fa8fa3e3c 100644 --- a/src/matchers/to-have-display-value.ts +++ b/src/matchers/to-have-display-value.ts @@ -1,5 +1,5 @@ import { matcherHint } from 'jest-matcher-utils'; -import type { HostElement } from 'test-renderer'; +import type { TestInstance } from 'test-renderer'; import { ErrorWithStack } from '../helpers/errors'; import { isHostTextInput } from '../helpers/host-component-names'; @@ -10,7 +10,7 @@ import { checkHostElement, formatMessage } from './utils'; export function toHaveDisplayValue( this: jest.MatcherContext, - element: HostElement, + element: TestInstance, expectedValue: TextMatch, options?: TextMatchOptions, ) { diff --git a/src/matchers/to-have-prop.ts b/src/matchers/to-have-prop.ts index 0b12902f8..fafa6ae29 100644 --- a/src/matchers/to-have-prop.ts +++ b/src/matchers/to-have-prop.ts @@ -1,11 +1,11 @@ import { matcherHint, printExpected, stringify } from 'jest-matcher-utils'; -import type { HostElement } from 'test-renderer'; +import type { TestInstance } from 'test-renderer'; import { checkHostElement, formatMessage } from './utils'; export function toHaveProp( this: jest.MatcherContext, - element: HostElement, + element: TestInstance, name: string, expectedValue: unknown, ) { diff --git a/src/matchers/to-have-style.ts b/src/matchers/to-have-style.ts index e5d304b49..acd4c7e28 100644 --- a/src/matchers/to-have-style.ts +++ b/src/matchers/to-have-style.ts @@ -1,7 +1,7 @@ import type { ImageStyle, StyleProp, TextStyle, ViewStyle } from 'react-native'; import { StyleSheet } from 'react-native'; import { diff, matcherHint } from 'jest-matcher-utils'; -import type { HostElement } from 'test-renderer'; +import type { TestInstance } from 'test-renderer'; import { checkHostElement, formatMessage } from './utils'; @@ -11,7 +11,7 @@ type StyleLike = Record; export function toHaveStyle( this: jest.MatcherContext, - element: HostElement, + element: TestInstance, style: StyleProp