mirror of
https://github.com/callstack/react-native-testing-library.git
synced 2026-09-18 23:09:04 +08:00
[v14] refactor: remove flow types (#1845)
This commit is contained in:
committed by
GitHub
parent
482875d410
commit
f534aa7ca6
-63
@@ -1,63 +0,0 @@
|
||||
[ignore]
|
||||
; We fork some components by platform
|
||||
.*/*[.]android.js
|
||||
.*/node_modules/.*\.json$
|
||||
|
||||
; Ignore "BUCK" generated dirs
|
||||
<PROJECT_ROOT>/\.buckd/
|
||||
|
||||
; Ignore polyfills
|
||||
node_modules/react-native/Libraries/polyfills/.*
|
||||
|
||||
; These should not be required directly
|
||||
; require from fbjs/lib instead: require('fbjs/lib/warning')
|
||||
node_modules/warning/.*
|
||||
|
||||
; Flow doesn't support platforms
|
||||
.*/Libraries/Utilities/LoadingView.js
|
||||
|
||||
[untyped]
|
||||
.*/node_modules/@react-native-community/cli/.*/.*
|
||||
|
||||
[include]
|
||||
.*/typings/
|
||||
|
||||
[libs]
|
||||
node_modules/react-native/interface.js
|
||||
node_modules/react-native/flow/
|
||||
flow-typed/
|
||||
.*/typings/index
|
||||
|
||||
[options]
|
||||
server.max_workers=4
|
||||
emoji=true
|
||||
|
||||
module.file_ext=.js
|
||||
module.file_ext=.json
|
||||
module.file_ext=.ios.js
|
||||
|
||||
munge_underscores=true
|
||||
|
||||
module.name_mapper='^react-native/\(.*\)$' -> '<PROJECT_ROOT>/node_modules/react-native/\1'
|
||||
module.name_mapper='^@?[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> '<PROJECT_ROOT>/node_modules/react-native/Libraries/Image/RelativeImageStub'
|
||||
|
||||
[lints]
|
||||
sketchy-null-number=warn
|
||||
sketchy-null-mixed=warn
|
||||
sketchy-number=warn
|
||||
untyped-type-import=warn
|
||||
nonstrict-import=warn
|
||||
deprecated-type=warn
|
||||
unsafe-getters-setters=warn
|
||||
unnecessary-invariant=warn
|
||||
signature-verification-failure=warn
|
||||
deprecated-utility=error
|
||||
|
||||
[strict]
|
||||
deprecated-type
|
||||
nonstrict-import
|
||||
sketchy-null
|
||||
unclear-type
|
||||
unsafe-getters-setters
|
||||
untyped-import
|
||||
untyped-type-import
|
||||
@@ -1,4 +1,2 @@
|
||||
node_modules/
|
||||
.yarn
|
||||
|
||||
flow-typed/
|
||||
|
||||
@@ -21,7 +21,7 @@ The project uses `yarn` for dependency management and script execution.
|
||||
- **Type Check:** `yarn typecheck` (Runs TypeScript compiler)
|
||||
- **Format Check:** `yarn prettier`
|
||||
- **Validate All:** `yarn validate` (Runs Prettier, ESLint, Typecheck, and Tests in sequence)
|
||||
- **Build Project:** `yarn build` (Cleans, builds JS with Babel, builds TS types, and copies Flow types)
|
||||
- **Build Project:** `yarn build` (Cleans, builds JS with Babel, and builds TS types)
|
||||
|
||||
## Development Conventions
|
||||
|
||||
|
||||
@@ -1,137 +0,0 @@
|
||||
# CLAUDE.md
|
||||
|
||||
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
||||
|
||||
## Project Overview
|
||||
|
||||
This is the **React Native Testing Library (RNTL)** - a comprehensive testing solution for React Native applications that provides React Native runtime simulation on top of `universal-test-renderer`. The library encourages better testing practices by focusing on testing behavior rather than implementation details.
|
||||
|
||||
## Key Development Commands
|
||||
|
||||
### Testing
|
||||
|
||||
- `yarn test` - Run all tests
|
||||
- `yarn test:ci` - Run tests with CI optimizations (maxWorkers=2)
|
||||
- `yarn test:ci:coverage` - Run tests with coverage reporting
|
||||
|
||||
### Building
|
||||
|
||||
- `yarn build` - Full build process (clean, build JS, build types, copy flow types)
|
||||
- `yarn build:js` - Build JavaScript using Babel
|
||||
- `yarn build:ts` - Build TypeScript declarations
|
||||
- `yarn clean` - Clean build directory
|
||||
|
||||
### Code Quality
|
||||
|
||||
- `yarn typecheck` - Run TypeScript compiler
|
||||
- `yarn lint` - Run ESLint with caching
|
||||
- `yarn validate` - Run lint + typecheck + test (pre-commit validation)
|
||||
|
||||
### Testing Single Files
|
||||
|
||||
To test a specific file: `yarn test path/to/test.test.tsx`
|
||||
|
||||
## Architecture Overview
|
||||
|
||||
### Core Components
|
||||
|
||||
1. **`src/index.ts`** - Main entry point that sets up auto-cleanup and extends Jest matchers
|
||||
2. **`src/pure.ts`** - Pure exports without auto-cleanup for advanced use cases
|
||||
3. **`src/render.tsx`** - Core rendering functionality using `universal-test-renderer`
|
||||
4. **`src/screen.ts`** - Global screen object providing access to rendered components
|
||||
|
||||
### Key Modules
|
||||
|
||||
- **`src/queries/`** - Query functions for finding elements (byText, byRole, byTestId, etc.)
|
||||
- **`src/matchers/`** - Jest matchers for assertions (toBeVisible, toHaveTextContent, etc.)
|
||||
- **`src/user-event/`** - User interaction simulation (press, type, scroll, etc.)
|
||||
- **`src/helpers/`** - Utility functions for component tree traversal and debugging
|
||||
- **`src/fire-event.ts`** - Low-level event firing utilities
|
||||
|
||||
### Query System
|
||||
|
||||
The library provides three query variants for each selector:
|
||||
|
||||
- `get*` - Throws if not found (for assertions)
|
||||
- `query*` - Returns null if not found (for conditional logic)
|
||||
- `find*` - Returns Promise, waits for element (for async operations)
|
||||
|
||||
### User Events vs Fire Events
|
||||
|
||||
- **User Events** (`src/user-event/`) - High-level, realistic user interactions
|
||||
- **Fire Events** (`src/fire-event.ts`) - Low-level, direct event dispatching
|
||||
|
||||
## Configuration
|
||||
|
||||
### Jest Setup
|
||||
|
||||
- Main Jest config: `jest.config.js`
|
||||
- Setup file: `jest-setup.ts`
|
||||
- Uses React Native preset with custom transform ignore patterns
|
||||
|
||||
### TypeScript
|
||||
|
||||
- Main config: `tsconfig.json` (development)
|
||||
- Release config: `tsconfig.release.json` (for builds)
|
||||
- Strict mode enabled with ES2022 target
|
||||
|
||||
### ESLint
|
||||
|
||||
- Config: `eslint.config.mjs`
|
||||
- Uses Callstack config + TypeScript strict rules
|
||||
- Custom rules for import sorting and test files
|
||||
|
||||
## Testing Patterns
|
||||
|
||||
### Component Testing
|
||||
|
||||
```jsx
|
||||
import { render, screen, userEvent } from '@testing-library/react-native';
|
||||
|
||||
test('component behavior', async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<MyComponent />);
|
||||
|
||||
await user.press(screen.getByRole('button'));
|
||||
expect(screen.getByText('Expected text')).toBeOnTheScreen();
|
||||
});
|
||||
```
|
||||
|
||||
### Async Testing
|
||||
|
||||
Use `findBy*` queries or `waitFor` for async operations:
|
||||
|
||||
```jsx
|
||||
const element = await screen.findByText('Async content');
|
||||
await waitFor(() => expect(mockFn).toHaveBeenCalled());
|
||||
```
|
||||
|
||||
## Development Workflow
|
||||
|
||||
1. **Working with Examples**: Test changes in `examples/` directory
|
||||
2. **Commit Messages**: Follow conventional commits (feat:, fix:, docs:, test:, chore:, refactor:, BREAKING:)
|
||||
3. **Pre-commit**: Hooks verify linting, type checking, and tests pass
|
||||
4. **Pull Requests**: Run `yarn validate` before submitting
|
||||
|
||||
## Build Process
|
||||
|
||||
The build creates:
|
||||
|
||||
- `build/` - Compiled JavaScript and TypeScript declarations
|
||||
- `matchers.js` - Jest matchers for separate import
|
||||
- `pure.js` - Pure version without auto-cleanup
|
||||
- `dont-cleanup-after-each.js` - Version without auto-cleanup
|
||||
|
||||
## Package Structure
|
||||
|
||||
- **Main exports**: Full library with auto-cleanup
|
||||
- **Pure exports**: Library without auto-cleanup (`/pure`)
|
||||
- **Matcher exports**: Jest matchers only (`/matchers`)
|
||||
- **No cleanup**: Disable auto-cleanup (`/dont-cleanup-after-each`)
|
||||
|
||||
## Testing Environment
|
||||
|
||||
- Uses `universal-test-renderer` for component rendering
|
||||
- Fake timers recommended for user events
|
||||
- String validation available for text rendering checks
|
||||
- Supports both concurrent and legacy React rendering modes
|
||||
@@ -12,7 +12,6 @@ module.exports = {
|
||||
],
|
||||
'@babel/preset-react',
|
||||
'@babel/preset-typescript',
|
||||
'@babel/preset-flow',
|
||||
],
|
||||
plugins: ['@babel/plugin-transform-strict-mode'],
|
||||
env: {
|
||||
|
||||
+1
-8
@@ -5,14 +5,7 @@ import jest from 'eslint-plugin-jest';
|
||||
|
||||
export default [
|
||||
{
|
||||
ignores: [
|
||||
'flow-typed/',
|
||||
'build/',
|
||||
'experiments-rtl/',
|
||||
'website/',
|
||||
'eslint.config.mjs',
|
||||
'jest-setup.ts',
|
||||
],
|
||||
ignores: ['build/', 'experiments-rtl/', 'website/', 'eslint.config.mjs', 'jest-setup.ts'],
|
||||
},
|
||||
...callstackConfig,
|
||||
...tseslint.configs.strict,
|
||||
|
||||
Vendored
-1218
File diff suppressed because it is too large
Load Diff
-81
@@ -1,81 +0,0 @@
|
||||
// flow-typed signature: b6bb53397d83d2d821e258cc73818d1b
|
||||
// flow-typed version: 9c71eca8ef/react-test-renderer_v16.x.x/flow_>=v0.47.x
|
||||
|
||||
// Type definitions for react-test-renderer 16.x.x
|
||||
// Ported from: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/react-test-renderer
|
||||
|
||||
type ReactComponentInstance = React$Component<any>;
|
||||
|
||||
type ReactTestRendererJSON = {
|
||||
type: string,
|
||||
props: { [propName: string]: any },
|
||||
children: null | ReactTestRendererJSON[],
|
||||
};
|
||||
|
||||
type ReactTestRendererTree = ReactTestRendererJSON & {
|
||||
nodeType: 'component' | 'host',
|
||||
instance: ?ReactComponentInstance,
|
||||
rendered: null | ReactTestRendererTree,
|
||||
};
|
||||
|
||||
type ReactTestInstance = {
|
||||
instance: ?ReactComponentInstance,
|
||||
type: string,
|
||||
props: { [propName: string]: any },
|
||||
parent: null | ReactTestInstance,
|
||||
children: Array<ReactTestInstance | string>,
|
||||
|
||||
find(predicate: (node: ReactTestInstance) => boolean): ReactTestInstance,
|
||||
findByType(type: React$ElementType): ReactTestInstance,
|
||||
findByProps(props: { [propName: string]: any }): ReactTestInstance,
|
||||
|
||||
findAll(
|
||||
predicate: (node: ReactTestInstance) => boolean,
|
||||
options?: { deep: boolean }
|
||||
): ReactTestInstance[],
|
||||
findAllByType(
|
||||
type: React$ElementType,
|
||||
options?: { deep: boolean }
|
||||
): ReactTestInstance[],
|
||||
findAllByProps(
|
||||
props: { [propName: string]: any },
|
||||
options?: { deep: boolean }
|
||||
): ReactTestInstance[],
|
||||
};
|
||||
|
||||
type TestRendererOptions = {
|
||||
createNodeMock(element: React$Element<any>): any,
|
||||
};
|
||||
|
||||
declare module 'react-test-renderer' {
|
||||
declare export type ReactTestRenderer = {
|
||||
toJSON(): null | ReactTestRendererJSON,
|
||||
toTree(): null | ReactTestRendererTree,
|
||||
unmount(nextElement?: React$Element<any>): void,
|
||||
update(nextElement: React$Element<any>): void,
|
||||
getInstance(): ?ReactComponentInstance,
|
||||
root: ReactTestInstance,
|
||||
};
|
||||
|
||||
declare type Thenable = {
|
||||
then(resolve: () => mixed, reject?: () => mixed): mixed,
|
||||
};
|
||||
|
||||
declare function create(
|
||||
nextElement: React$Element<any>,
|
||||
options?: TestRendererOptions
|
||||
): ReactTestRenderer;
|
||||
|
||||
declare function act(callback: () => void): Thenable;
|
||||
}
|
||||
|
||||
declare module 'react-test-renderer/shallow' {
|
||||
declare export default class ShallowRenderer {
|
||||
static createRenderer(): ShallowRenderer;
|
||||
getMountedInstance(): ReactTestInstance;
|
||||
getRenderOutput<E: React$Element<any>>(): E;
|
||||
getRenderOutput(): React$Element<any>;
|
||||
render(element: React$Element<any>, context?: any): void;
|
||||
unmount(): void;
|
||||
}
|
||||
}
|
||||
+2
-6
@@ -28,12 +28,11 @@
|
||||
"test:ci": "jest --maxWorkers=2",
|
||||
"test:ci:coverage": "jest --maxWorkers=2 --collectCoverage=true --coverage-provider=v8",
|
||||
"typecheck": "tsc",
|
||||
"copy-flowtypes": "cp typings/index.flow.js build",
|
||||
"lint": "eslint src --cache",
|
||||
"validate": "yarn prettier && yarn lint && yarn typecheck && yarn test",
|
||||
"build:js": "babel src --out-dir build --extensions \".js,.ts,.jsx,.tsx\" --source-maps --ignore \"**/__tests__/**\"",
|
||||
"build:ts": "tsc --build tsconfig.release.json",
|
||||
"build": "yarn clean && yarn build:js && yarn build:ts && yarn copy-flowtypes",
|
||||
"build": "yarn clean && yarn build:js && yarn build:ts",
|
||||
"release": "release-it",
|
||||
"release:rc": "release-it --preRelease=rc",
|
||||
"release:alpha": "release-it --preRelease=alpha",
|
||||
@@ -46,8 +45,7 @@
|
||||
"matchers.d.ts",
|
||||
"pure.js",
|
||||
"pure.d.ts",
|
||||
"dont-cleanup-after-each.js",
|
||||
"typings/index.flow.js"
|
||||
"dont-cleanup-after-each.js"
|
||||
],
|
||||
"dependencies": {
|
||||
"jest-matcher-utils": "^30.2.0",
|
||||
@@ -71,7 +69,6 @@
|
||||
"@babel/core": "^7.28.5",
|
||||
"@babel/plugin-transform-strict-mode": "^7.27.1",
|
||||
"@babel/preset-env": "^7.28.5",
|
||||
"@babel/preset-flow": "^7.27.1",
|
||||
"@babel/preset-react": "^7.28.5",
|
||||
"@babel/preset-typescript": "^7.28.5",
|
||||
"@callstack/eslint-config": "^15.0.0",
|
||||
@@ -86,7 +83,6 @@
|
||||
"del-cli": "^7.0.0",
|
||||
"eslint": "^9.39.1",
|
||||
"eslint-plugin-simple-import-sort": "^12.1.1",
|
||||
"flow-bin": "~0.170.0",
|
||||
"jest": "^30.2.0",
|
||||
"prettier": "^3.6.2",
|
||||
"react": "19.1.1",
|
||||
|
||||
@@ -1,391 +0,0 @@
|
||||
// @flow
|
||||
import * as React from 'react';
|
||||
|
||||
type GetReturn = ReactTestInstance;
|
||||
type GetAllReturn = Array<ReactTestInstance>;
|
||||
type QueryReturn = ReactTestInstance | null;
|
||||
type QueryAllReturn = Array<ReactTestInstance> | [];
|
||||
type FindReturn = Promise<ReactTestInstance>;
|
||||
type FindAllReturn = Promise<ReactTestInstance[]>;
|
||||
|
||||
type CommonQueryOptions = {
|
||||
includeHiddenElements?: boolean,
|
||||
hidden?: boolean,
|
||||
};
|
||||
|
||||
type TextMatch = string | RegExp;
|
||||
|
||||
declare type NormalizerFn = (textToNormalize: string) => string;
|
||||
declare type NormalizerConfig = {
|
||||
trim?: boolean,
|
||||
collapseWhitespace?: boolean,
|
||||
};
|
||||
declare type TextMatchOptions = {
|
||||
exact?: boolean,
|
||||
normalizer?: NormalizerFn,
|
||||
};
|
||||
declare type A11yRole =
|
||||
| 'none'
|
||||
| 'button'
|
||||
| 'link'
|
||||
| 'search'
|
||||
| 'image'
|
||||
| 'keyboardkey'
|
||||
| 'text'
|
||||
| 'adjustable'
|
||||
| 'imagebutton'
|
||||
| 'header'
|
||||
| 'summary'
|
||||
| 'alert'
|
||||
| 'checkbox'
|
||||
| 'combobox'
|
||||
| 'menu'
|
||||
| 'menubar'
|
||||
| 'menuitem'
|
||||
| 'progressbar'
|
||||
| 'radio'
|
||||
| 'radiogroup'
|
||||
| 'scrollbar'
|
||||
| 'spinbutton'
|
||||
| 'switch'
|
||||
| 'tab'
|
||||
| 'tablist'
|
||||
| 'timer'
|
||||
| 'toolbar';
|
||||
|
||||
declare type A11yState = {|
|
||||
disabled?: boolean,
|
||||
selected?: boolean,
|
||||
checked?: boolean | 'mixed',
|
||||
busy?: boolean,
|
||||
expanded?: boolean,
|
||||
|};
|
||||
|
||||
declare type A11yValue = {
|
||||
min?: number,
|
||||
max?: number,
|
||||
now?: number,
|
||||
text?: TextMatch,
|
||||
};
|
||||
|
||||
type WaitForOptions = {
|
||||
timeout?: number,
|
||||
interval?: number,
|
||||
onTimeout?: (error: Error) => Error,
|
||||
};
|
||||
|
||||
type WaitForFunction = <T = any>(expectation: () => T, options?: WaitForOptions) => Promise<T>;
|
||||
|
||||
type ByTextOptions = CommonQueryOptions & TextMatchOptions;
|
||||
|
||||
interface ByTextQueries {
|
||||
getByText: (text: TextMatch, options?: ByTextOptions) => ReactTestInstance;
|
||||
getAllByText: (text: TextMatch, options?: ByTextOptions) => Array<ReactTestInstance>;
|
||||
queryByText: (name: TextMatch, options?: ByTextOptions) => ReactTestInstance | null;
|
||||
queryAllByText: (text: TextMatch, options?: ByTextOptions) => Array<ReactTestInstance> | [];
|
||||
findByText: (
|
||||
text: TextMatch,
|
||||
queryOptions?: ByTextOptions,
|
||||
waitForOptions?: WaitForOptions,
|
||||
) => FindReturn;
|
||||
findAllByText: (
|
||||
text: TextMatch,
|
||||
queryOptions?: ByTextOptions,
|
||||
waitForOptions?: WaitForOptions,
|
||||
) => FindAllReturn;
|
||||
}
|
||||
|
||||
type ByTestIdOptions = CommonQueryOptions & TextMatchOptions;
|
||||
|
||||
interface ByTestIdQueries {
|
||||
getByTestId: (testID: TextMatch, options?: ByTestIdOptions) => ReactTestInstance;
|
||||
getAllByTestId: (testID: TextMatch, options?: ByTestIdOptions) => Array<ReactTestInstance>;
|
||||
queryByTestId: (testID: TextMatch, options?: ByTestIdOptions) => ReactTestInstance | null;
|
||||
queryAllByTestId: (testID: TextMatch, options?: ByTestIdOptions) => Array<ReactTestInstance> | [];
|
||||
findByTestId: (
|
||||
testID: TextMatch,
|
||||
queryOptions?: ByTestIdOptions,
|
||||
waitForOptions?: WaitForOptions,
|
||||
) => FindReturn;
|
||||
findAllByTestId: (
|
||||
testID: TextMatch,
|
||||
queryOptions?: ByTestIdOptions,
|
||||
waitForOptions?: WaitForOptions,
|
||||
) => FindAllReturn;
|
||||
}
|
||||
|
||||
type ByDisplayValueOptions = CommonQueryOptions & TextMatchOptions;
|
||||
|
||||
interface ByDisplayValueQueries {
|
||||
getByDisplayValue: (value: TextMatch, options?: ByDisplayValueOptions) => ReactTestInstance;
|
||||
getAllByDisplayValue: (
|
||||
value: TextMatch,
|
||||
options?: ByDisplayValueOptions,
|
||||
) => Array<ReactTestInstance>;
|
||||
queryByDisplayValue: (
|
||||
value: TextMatch,
|
||||
options?: ByDisplayValueOptions,
|
||||
) => ReactTestInstance | null;
|
||||
queryAllByDisplayValue: (
|
||||
value: TextMatch,
|
||||
options?: ByDisplayValueOptions,
|
||||
) => Array<ReactTestInstance> | [];
|
||||
findByDisplayValue: (
|
||||
value: TextMatch,
|
||||
queryOptions?: ByDisplayValueOptions,
|
||||
waitForOptions?: WaitForOptions,
|
||||
) => FindReturn;
|
||||
findAllByDisplayValue: (
|
||||
value: TextMatch,
|
||||
queryOptions?: ByDisplayValueOptions,
|
||||
waitForOptions?: WaitForOptions,
|
||||
) => FindAllReturn;
|
||||
}
|
||||
|
||||
type ByPlaceholderTextOptions = CommonQueryOptions & TextMatchOptions;
|
||||
|
||||
interface ByPlaceholderTextQueries {
|
||||
getByPlaceholderText: (
|
||||
placeholder: TextMatch,
|
||||
options?: ByPlaceholderTextOptions,
|
||||
) => ReactTestInstance;
|
||||
getAllByPlaceholderText: (
|
||||
placeholder: TextMatch,
|
||||
options?: ByPlaceholderTextOptions,
|
||||
) => Array<ReactTestInstance>;
|
||||
queryByPlaceholderText: (
|
||||
placeholder: TextMatch,
|
||||
options?: ByPlaceholderTextOptions,
|
||||
) => ReactTestInstance | null;
|
||||
queryAllByPlaceholderText: (
|
||||
placeholder: TextMatch,
|
||||
options?: ByPlaceholderTextOptions,
|
||||
) => Array<ReactTestInstance> | [];
|
||||
findByPlaceholderText: (
|
||||
placeholder: TextMatch,
|
||||
queryOptions?: ByPlaceholderTextOptions,
|
||||
waitForOptions?: WaitForOptions,
|
||||
) => FindReturn;
|
||||
findAllByPlaceholderText: (
|
||||
placeholder: TextMatch,
|
||||
queryOptions?: ByPlaceholderTextOptions,
|
||||
waitForOptions?: WaitForOptions,
|
||||
) => FindAllReturn;
|
||||
}
|
||||
|
||||
interface UnsafeByTypeQueries {
|
||||
UNSAFE_getByType: <P>(type: React.ComponentType<P>) => ReactTestInstance;
|
||||
UNSAFE_getAllByType: <P>(type: React.ComponentType<P>) => Array<ReactTestInstance>;
|
||||
UNSAFE_queryByType: <P>(type: React.ComponentType<P>) => ReactTestInstance | null;
|
||||
UNSAFE_queryAllByType: <P>(type: React.ComponentType<P>) => Array<ReactTestInstance> | [];
|
||||
}
|
||||
|
||||
interface UnsafeByPropsQueries {
|
||||
UNSAFE_getByProps: (props: { [string]: any }) => ReactTestInstance;
|
||||
UNSAFE_getAllByProps: (props: { [string]: any }) => Array<ReactTestInstance>;
|
||||
UNSAFE_queryByProps: (props: { [string]: any }) => ReactTestInstance | null;
|
||||
UNSAFE_queryAllByProps: (props: { [string]: any }) => Array<ReactTestInstance> | [];
|
||||
}
|
||||
|
||||
type ByRoleOptions = CommonQueryOptions & {
|
||||
...A11yState,
|
||||
name?: string,
|
||||
value?: A11yValue,
|
||||
};
|
||||
|
||||
type ByLabelTextOptions = CommonQueryOptions & TextMatchOptions;
|
||||
type ByHintTextOptions = CommonQueryOptions & TextMatchOptions;
|
||||
|
||||
interface A11yAPI {
|
||||
// Label
|
||||
getByLabelText: (matcher: TextMatch, options?: ByLabelTextOptions) => GetReturn;
|
||||
getAllByLabelText: (matcher: TextMatch, options?: ByLabelTextOptions) => GetAllReturn;
|
||||
queryByLabelText: (matcher: TextMatch, options?: ByLabelTextOptions) => QueryReturn;
|
||||
queryAllByLabelText: (matcher: TextMatch, options?: ByLabelTextOptions) => QueryAllReturn;
|
||||
findByLabelText: (
|
||||
matcher: TextMatch,
|
||||
queryOptions?: ByLabelTextOptions,
|
||||
waitForOptions?: WaitForOptions,
|
||||
) => FindReturn;
|
||||
findAllByLabelText: (
|
||||
matcher: TextMatch,
|
||||
queryOptions?: ByLabelTextOptions,
|
||||
waitForOptions?: WaitForOptions,
|
||||
) => FindAllReturn;
|
||||
|
||||
// Hint
|
||||
getByA11yHint: (matcher: TextMatch, options?: ByHintTextOptions) => GetReturn;
|
||||
getByHintText: (matcher: TextMatch, options?: ByHintTextOptions) => GetReturn;
|
||||
getAllByA11yHint: (matcher: TextMatch, options?: ByHintTextOptions) => GetAllReturn;
|
||||
getAllByHintText: (matcher: TextMatch, options?: ByHintTextOptions) => GetAllReturn;
|
||||
queryByA11yHint: (matcher: TextMatch, options?: ByHintTextOptions) => QueryReturn;
|
||||
queryByHintText: (matcher: TextMatch, options?: ByHintTextOptions) => QueryReturn;
|
||||
queryAllByA11yHint: (matcher: TextMatch, options?: ByHintTextOptions) => QueryAllReturn;
|
||||
queryAllByHintText: (matcher: TextMatch, options?: ByHintTextOptions) => QueryAllReturn;
|
||||
findByA11yHint: (
|
||||
matcher: TextMatch,
|
||||
queryOptions?: ByHintTextOptions,
|
||||
waitForOptions?: WaitForOptions,
|
||||
) => FindReturn;
|
||||
findByHintText: (
|
||||
matcher: TextMatch,
|
||||
queryOptions?: ByHintTextOptions,
|
||||
waitForOptions?: WaitForOptions,
|
||||
) => FindReturn;
|
||||
findAllByA11yHint: (
|
||||
matcher: TextMatch,
|
||||
queryOptions?: ByHintTextOptions,
|
||||
waitForOptions?: WaitForOptions,
|
||||
) => FindAllReturn;
|
||||
findAllByHintText: (
|
||||
matcher: TextMatch,
|
||||
queryOptions?: ByHintTextOptions,
|
||||
waitForOptions?: WaitForOptions,
|
||||
) => FindAllReturn;
|
||||
|
||||
// Role
|
||||
getByRole: (matcher: A11yRole | RegExp, role?: ByRoleOptions) => GetReturn;
|
||||
getAllByRole: (matcher: A11yRole | RegExp, options?: ByRoleOptions) => GetAllReturn;
|
||||
queryByRole: (matcher: A11yRole | RegExp, options?: ByRoleOptions) => QueryReturn;
|
||||
queryAllByRole: (matcher: A11yRole | RegExp, options?: ByRoleOptions) => QueryAllReturn;
|
||||
findByRole: (
|
||||
matcher: A11yRole | RegExp,
|
||||
queryOptions?: ByRoleOptions,
|
||||
waitForOptions?: WaitForOptions,
|
||||
) => FindReturn;
|
||||
findAllByRole: (
|
||||
matcher: A11yRole | RegExp,
|
||||
queryOptions?: ByRoleOptions,
|
||||
waitForOptions?: WaitForOptions,
|
||||
) => FindAllReturn;
|
||||
}
|
||||
|
||||
interface Thenable {
|
||||
then: (resolve: () => any, reject?: () => any) => any;
|
||||
}
|
||||
|
||||
type MapPropsFunction = (
|
||||
props: { [string]: mixed },
|
||||
node: ReactTestRendererJSON,
|
||||
) => { [string]: mixed };
|
||||
|
||||
type DebugOptions = {
|
||||
message?: string,
|
||||
mapProps?: MapPropsFunction,
|
||||
};
|
||||
|
||||
type Queries = ByTextQueries &
|
||||
ByTestIdQueries &
|
||||
ByDisplayValueQueries &
|
||||
ByPlaceholderTextQueries &
|
||||
UnsafeByTypeQueries &
|
||||
UnsafeByPropsQueries &
|
||||
A11yAPI;
|
||||
|
||||
type FireEventFunction = (
|
||||
element: ReactTestInstance,
|
||||
eventName: string,
|
||||
...data: Array<any>
|
||||
) => Promise<any>;
|
||||
|
||||
type FireEventAPI = FireEventFunction & {
|
||||
press: (element: ReactTestInstance, ...data: Array<any>) => Promise<any>,
|
||||
changeText: (element: ReactTestInstance, ...data: Array<any>) => Promise<any>,
|
||||
scroll: (element: ReactTestInstance, ...data: Array<any>) => Promise<any>,
|
||||
};
|
||||
|
||||
type DeprecatedFireEventSyncFunction = (
|
||||
element: ReactTestInstance,
|
||||
eventName: string,
|
||||
...data: Array<any>
|
||||
) => any;
|
||||
|
||||
type DeprecatedFireEventSyncAPI = DeprecatedFireEventSyncFunction & {
|
||||
press: (element: ReactTestInstance, ...data: Array<any>) => any,
|
||||
changeText: (element: ReactTestInstance, ...data: Array<any>) => any,
|
||||
scroll: (element: ReactTestInstance, ...data: Array<any>) => any,
|
||||
};
|
||||
|
||||
declare module '@testing-library/react-native' {
|
||||
declare interface RenderResult extends Queries {
|
||||
update(nextElement: React.Element<any>): void;
|
||||
rerender(nextElement: React.Element<any>): void;
|
||||
unmount(nextElement?: React.Element<any>): void;
|
||||
toJSON(): ReactTestRendererJSON[] | ReactTestRendererJSON | null;
|
||||
debug(options?: DebugOptions): void;
|
||||
root: ReactTestInstance;
|
||||
UNSAFE_root: ReactTestInstance;
|
||||
}
|
||||
|
||||
declare type RenderAPI = RenderResult;
|
||||
|
||||
declare interface RenderOptions {
|
||||
wrapper?: React.ComponentType<any>;
|
||||
createNodeMock?: (element: React.Element<any>) => any;
|
||||
unstable_validateStringsRenderedWithinText?: boolean;
|
||||
unstable_isConcurrent?: boolean;
|
||||
unstable_strictMode?: boolean;
|
||||
unstable_concurrentUpdatesByDefault?: boolean;
|
||||
}
|
||||
|
||||
declare export var render: (
|
||||
component: React.Element<any>,
|
||||
options?: RenderOptions,
|
||||
) => RenderResult;
|
||||
|
||||
declare export var screen: RenderResult;
|
||||
|
||||
declare export var cleanup: () => void;
|
||||
declare export var fireEvent: FireEventAPI;
|
||||
declare export var deprecated_fireEventSync: DeprecatedFireEventSyncAPI;
|
||||
|
||||
declare export var waitFor: WaitForFunction;
|
||||
|
||||
declare type WaitForElementToBeRemovedFunction = <T = any>(
|
||||
expectation: () => T,
|
||||
options?: WaitForOptions,
|
||||
) => Promise<T>;
|
||||
|
||||
declare export var waitForElementToBeRemoved: WaitForElementToBeRemovedFunction;
|
||||
|
||||
declare interface Config {
|
||||
asyncUtilTimeout: number;
|
||||
defaultIncludeHiddenElements: boolean;
|
||||
defaultDebugOptions?: $Shape<DebugOptions>;
|
||||
}
|
||||
|
||||
declare interface ConfigAliasOptions {
|
||||
/** Alias to `defaultIncludeHiddenElements` for RTL compatibility */
|
||||
defaultHidden: boolean;
|
||||
}
|
||||
|
||||
declare export var configure: (options: $Shape<Config & ConfigAliasOptions>) => void;
|
||||
declare export var resetToDefaults: () => void;
|
||||
|
||||
declare export var act: (callback: () => void) => Thenable;
|
||||
declare export var within: (instance: ReactTestInstance) => Queries;
|
||||
declare export var getQueriesForElement: (element: ReactTestInstance) => Queries;
|
||||
|
||||
declare export var getDefaultNormalizer: (normalizerConfig?: NormalizerConfig) => NormalizerFn;
|
||||
|
||||
declare export var isHiddenFromAccessibility: (element: ReactTestInstance | null) => boolean;
|
||||
declare export var isInaccessible: (element: ReactTestInstance | null) => boolean;
|
||||
|
||||
declare type RenderHookResult<Result, Props> = {
|
||||
rerender: (props: Props) => void,
|
||||
result: { current: Result },
|
||||
unmount: () => void,
|
||||
};
|
||||
|
||||
declare type RenderHookOptions<Props> = {
|
||||
initialProps?: Props,
|
||||
wrapper?: React.ComponentType<any>,
|
||||
};
|
||||
|
||||
declare type RenderHookFunction = <Result, Props>(
|
||||
renderCallback: (props: Props) => Result,
|
||||
options?: RenderHookOptions<Props>,
|
||||
) => RenderHookResult<Result, Props>;
|
||||
|
||||
declare export var renderHook: RenderHookFunction;
|
||||
}
|
||||
@@ -837,7 +837,7 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@babel/plugin-transform-flow-strip-types@npm:^7.25.2, @babel/plugin-transform-flow-strip-types@npm:^7.27.1":
|
||||
"@babel/plugin-transform-flow-strip-types@npm:^7.25.2":
|
||||
version: 7.27.1
|
||||
resolution: "@babel/plugin-transform-flow-strip-types@npm:7.27.1"
|
||||
dependencies:
|
||||
@@ -1440,19 +1440,6 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@babel/preset-flow@npm:^7.27.1":
|
||||
version: 7.27.1
|
||||
resolution: "@babel/preset-flow@npm:7.27.1"
|
||||
dependencies:
|
||||
"@babel/helper-plugin-utils": "npm:^7.27.1"
|
||||
"@babel/helper-validator-option": "npm:^7.27.1"
|
||||
"@babel/plugin-transform-flow-strip-types": "npm:^7.27.1"
|
||||
peerDependencies:
|
||||
"@babel/core": ^7.0.0-0
|
||||
checksum: 10c0/252216c91ba3cc126f10c81c1df495ef2c622687d17373bc619354a7fb7280ea83f434ed1e7149dbddd712790d16ab60f5b864d007edd153931d780f834e52c1
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@babel/preset-modules@npm:0.1.6-no-external-plugins":
|
||||
version: 0.1.6-no-external-plugins
|
||||
resolution: "@babel/preset-modules@npm:0.1.6-no-external-plugins"
|
||||
@@ -3027,7 +3014,6 @@ __metadata:
|
||||
"@babel/core": "npm:^7.28.5"
|
||||
"@babel/plugin-transform-strict-mode": "npm:^7.27.1"
|
||||
"@babel/preset-env": "npm:^7.28.5"
|
||||
"@babel/preset-flow": "npm:^7.27.1"
|
||||
"@babel/preset-react": "npm:^7.28.5"
|
||||
"@babel/preset-typescript": "npm:^7.28.5"
|
||||
"@callstack/eslint-config": "npm:^15.0.0"
|
||||
@@ -3042,7 +3028,6 @@ __metadata:
|
||||
del-cli: "npm:^7.0.0"
|
||||
eslint: "npm:^9.39.1"
|
||||
eslint-plugin-simple-import-sort: "npm:^12.1.1"
|
||||
flow-bin: "npm:~0.170.0"
|
||||
jest: "npm:^30.2.0"
|
||||
jest-matcher-utils: "npm:^30.2.0"
|
||||
picocolors: "npm:^1.1.1"
|
||||
@@ -5845,15 +5830,6 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"flow-bin@npm:~0.170.0":
|
||||
version: 0.170.0
|
||||
resolution: "flow-bin@npm:0.170.0"
|
||||
bin:
|
||||
flow: cli.js
|
||||
checksum: 10c0/cdb54136cc334915ef788350f9b6c87024ddda2b676a70497fa38da05b373171d61f27f23796e625cdc3f96019dc05be9aadd629332335e8b1a9d40ba21605bd
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"flow-enums-runtime@npm:^0.0.6":
|
||||
version: 0.0.6
|
||||
resolution: "flow-enums-runtime@npm:0.0.6"
|
||||
|
||||
Reference in New Issue
Block a user