mirror of
https://github.com/callstack/react-native-testing-library.git
synced 2026-09-18 23:09:04 +08:00
basic setup
This commit is contained in:
@@ -3,7 +3,7 @@ on:
|
||||
push:
|
||||
branches: [main]
|
||||
pull_request:
|
||||
branches: ['**']
|
||||
branches: ["**"]
|
||||
|
||||
# Set minimal permissions by default
|
||||
permissions:
|
||||
@@ -27,8 +27,8 @@ jobs:
|
||||
- name: Lint
|
||||
run: yarn lint
|
||||
|
||||
- name: Prettier
|
||||
run: yarn prettier
|
||||
- name: Format
|
||||
run: yarn format
|
||||
|
||||
typecheck:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"$schema": "./node_modules/oxfmt/configuration_schema.json",
|
||||
"singleQuote": true,
|
||||
"ignorePatterns": ["node_modules/", ".yarn", "codemods/**/tests/fixtures/**"],
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
node_modules/
|
||||
.yarn
|
||||
codemods/**/tests/fixtures/**
|
||||
@@ -25,15 +25,15 @@ The project uses `yarn` for dependency management and script execution.
|
||||
- **Run Tests (CI):** `yarn test:ci` (Runs Jest with worker limits)
|
||||
- **Lint Code:** `yarn lint` (Runs ESLint on `src`)
|
||||
- **Type Check:** `yarn typecheck` (Runs TypeScript compiler)
|
||||
- **Format Check:** `yarn prettier`
|
||||
- **Validate All:** `yarn validate` (Runs Prettier, ESLint, Typecheck, and Tests in sequence)
|
||||
- **Format Check:** `yarn format` (Runs Oxfmt)
|
||||
- **Validate All:** `yarn validate` (Runs Oxfmt, ESLint, Typecheck, and Tests in sequence)
|
||||
- **Build Project:** `yarn build` (Cleans, builds JS with Babel, and builds TS types)
|
||||
|
||||
## Development Conventions
|
||||
|
||||
- **Code Style:**
|
||||
- **Linting:** ESLint is configured with `@callstack/eslint-config` and `typescript-eslint`. It enforces strict rules, including `no-console` and consistent type imports.
|
||||
- **Formatting:** Prettier is used for code formatting (single quotes, trailing commas).
|
||||
- **Formatting:** Oxfmt is used for code formatting (single quotes, trailing commas).
|
||||
- **Imports:** Sorted using `eslint-plugin-simple-import-sort`.
|
||||
|
||||
- **Testing:**
|
||||
|
||||
@@ -6,6 +6,6 @@
|
||||
"scripts": {
|
||||
"test": "node --loader tsx/esm scripts/test.js"
|
||||
},
|
||||
"devDependencies": {},
|
||||
"dependencies": {}
|
||||
"dependencies": {},
|
||||
"devDependencies": {}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ export default [
|
||||
'no-console': 'error',
|
||||
'import/order': 'off',
|
||||
'@typescript-eslint/consistent-type-imports': 'error',
|
||||
'prettier/prettier': 'off',
|
||||
},
|
||||
},
|
||||
{
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
{
|
||||
"private": true,
|
||||
"main": "node_modules/expo/AppEntry.js",
|
||||
"scripts": {
|
||||
"start": "expo start",
|
||||
@@ -29,6 +30,5 @@
|
||||
"react-test-renderer": "19.0.0",
|
||||
"typescript": "^5.3.0"
|
||||
},
|
||||
"private": true,
|
||||
"packageManager": "yarn@4.0.1"
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
{
|
||||
"private": true,
|
||||
"main": "expo-router/entry",
|
||||
"scripts": {
|
||||
"start": "expo start",
|
||||
@@ -42,6 +43,5 @@
|
||||
"react-test-renderer": "19.0.0",
|
||||
"typescript": "~5.8.3"
|
||||
},
|
||||
"private": true,
|
||||
"packageManager": "yarn@4.0.1"
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
{
|
||||
"name": "experiments-app",
|
||||
"version": "1.0.0",
|
||||
"private": true,
|
||||
"description": "Expo app for conducting experiments of React Native behaviour.",
|
||||
"version": "1.0.0",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"typecheck": "tsc -noEmit",
|
||||
|
||||
+40
-40
@@ -2,26 +2,37 @@
|
||||
"name": "@testing-library/react-native",
|
||||
"version": "14.0.0-beta.0",
|
||||
"description": "Simple and complete React Native testing utilities that encourage good testing practices.",
|
||||
"main": "build/index.js",
|
||||
"types": "build/index.d.ts",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://www.github.com/callstack/react-native-testing-library.git"
|
||||
},
|
||||
"keywords": [
|
||||
"integration",
|
||||
"react",
|
||||
"react-native",
|
||||
"test"
|
||||
],
|
||||
"homepage": "https://oss.callstack.com/react-native-testing-library",
|
||||
"license": "MIT",
|
||||
"author": "Maciej Jastrzębski <mdjastrzebski@gmail.com> (https://github.com/mdjastrzebski), Michał Pierzchała <thymikee@gmail.com> (https://github.com/thymikee)",
|
||||
"contributors": [
|
||||
"Augustin Le Fèvre <augustin.le-fevre@klarna.com> (https://github.com/AugustinLF)",
|
||||
"Pierre Zimmermann <pierrez@nam.tech> (https://github.com/pierrezimmermannbam)",
|
||||
"MattAgn <matthieua@bam.tech> (https://github.com/MattAgn)"
|
||||
],
|
||||
"license": "MIT",
|
||||
"keywords": [
|
||||
"react-native",
|
||||
"react",
|
||||
"test",
|
||||
"integration"
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://www.github.com/callstack/react-native-testing-library.git"
|
||||
},
|
||||
"files": [
|
||||
"dont-cleanup-after-each.js",
|
||||
"matchers.d.ts",
|
||||
"matchers.js",
|
||||
"pure.d.ts",
|
||||
"pure.js",
|
||||
"build/"
|
||||
],
|
||||
"main": "build/index.js",
|
||||
"types": "build/index.d.ts",
|
||||
"publishConfig": {
|
||||
"registry": "https://registry.npmjs.org"
|
||||
},
|
||||
"scripts": {
|
||||
"clean": "del build",
|
||||
"test": "jest",
|
||||
@@ -30,10 +41,10 @@
|
||||
"test:codemods": "node scripts/test-codemods.mjs",
|
||||
"typecheck": "tsc",
|
||||
"lint": "eslint src --cache",
|
||||
"prettier": "prettier --check .",
|
||||
"prettier:fix": "prettier --write .",
|
||||
"validate": "yarn typecheck && yarn test && yarn lint && yarn prettier",
|
||||
"validate:fix": "yarn prettier:fix && yarn lint --fix && yarn typecheck && yarn test -u",
|
||||
"format": "oxfmt --check",
|
||||
"format:fix": "oxfmt",
|
||||
"validate": "yarn typecheck && yarn test && yarn lint && yarn format",
|
||||
"validate:fix": "yarn format:fix && yarn lint --fix && yarn typecheck && yarn test -u",
|
||||
"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",
|
||||
@@ -42,31 +53,12 @@
|
||||
"release:beta": "release-it --preRelease=beta",
|
||||
"release:codemods": "release-it --preRelease=alpha"
|
||||
},
|
||||
"files": [
|
||||
"build/",
|
||||
"matchers.js",
|
||||
"matchers.d.ts",
|
||||
"pure.js",
|
||||
"pure.d.ts",
|
||||
"dont-cleanup-after-each.js"
|
||||
],
|
||||
"dependencies": {
|
||||
"jest-matcher-utils": "^30.2.0",
|
||||
"picocolors": "^1.1.1",
|
||||
"pretty-format": "^30.2.0",
|
||||
"redent": "^3.0.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"jest": ">=29.0.0",
|
||||
"react": ">=19.0.0",
|
||||
"react-native": ">=0.78",
|
||||
"test-renderer": "^0.14.0"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"jest": {
|
||||
"optional": true
|
||||
}
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/cli": "^7.28.3",
|
||||
"@babel/core": "^7.28.5",
|
||||
@@ -87,7 +79,7 @@
|
||||
"eslint": "^9.39.1",
|
||||
"eslint-plugin-simple-import-sort": "^12.1.1",
|
||||
"jest": "^30.2.0",
|
||||
"prettier": "^3.6.2",
|
||||
"oxfmt": "^0.26.0",
|
||||
"react": "19.2.0",
|
||||
"react-native": "0.83.1",
|
||||
"react-native-gesture-handler": "^2.29.1",
|
||||
@@ -96,11 +88,19 @@
|
||||
"typescript": "^5.9.3",
|
||||
"typescript-eslint": "^8.47.0"
|
||||
},
|
||||
"publishConfig": {
|
||||
"registry": "https://registry.npmjs.org"
|
||||
"peerDependencies": {
|
||||
"jest": ">=29.0.0",
|
||||
"react": ">=19.0.0",
|
||||
"react-native": ">=0.78",
|
||||
"test-renderer": "^0.14.0"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"jest": {
|
||||
"optional": true
|
||||
}
|
||||
},
|
||||
"packageManager": "yarn@4.11.0",
|
||||
"engines": {
|
||||
"node": ">=20"
|
||||
}
|
||||
},
|
||||
"packageManager": "yarn@4.11.0"
|
||||
}
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
// added for Jest inline snapshots to not use default Prettier config
|
||||
module.exports = {
|
||||
singleQuote: true,
|
||||
trailingComma: 'all',
|
||||
};
|
||||
@@ -32,7 +32,7 @@ test('User can sign in with correct credentials', async () => {
|
||||
|
||||
// Follow-up assertions do not need to be async, as we already waited for sign in operation to complete
|
||||
expect(
|
||||
screen.queryByRole('header', { name: 'Sign in to Hello World App' })
|
||||
screen.queryByRole('header', { name: 'Sign in to Hello World App' }),
|
||||
).not.toBeOnTheScreen();
|
||||
expect(screen.queryByLabelText('Username')).not.toBeOnTheScreen();
|
||||
expect(screen.queryByLabelText('Password')).not.toBeOnTheScreen();
|
||||
@@ -87,7 +87,7 @@ function waitFor<T>(
|
||||
options?: {
|
||||
timeout: number;
|
||||
interval: number;
|
||||
}
|
||||
},
|
||||
): Promise<T>;
|
||||
```
|
||||
|
||||
@@ -111,7 +111,7 @@ function waitForElementToBeRemoved<T>(
|
||||
options?: {
|
||||
timeout: number;
|
||||
interval: number;
|
||||
}
|
||||
},
|
||||
): Promise<T> {}
|
||||
```
|
||||
|
||||
|
||||
@@ -16,12 +16,12 @@ interface RenderWithProvidersProps {
|
||||
|
||||
export function renderWithProviders<T>(
|
||||
ui: React.ReactElement<T>,
|
||||
options?: RenderWithProvidersProps
|
||||
options?: RenderWithProvidersProps,
|
||||
) {
|
||||
return render(
|
||||
<UserProvider.Provider value={options?.user ?? null}>
|
||||
<ThemeProvider.Provider value={options?.theme ?? 'light'}>{ui}</ThemeProvider.Provider>
|
||||
</UserProvider.Provider>
|
||||
</UserProvider.Provider>,
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
@@ -110,10 +110,10 @@ export interface RenderWithAtomsOptions {
|
||||
*/
|
||||
export const renderWithAtoms = <T,>(
|
||||
component: React.ReactElement,
|
||||
options: RenderWithAtomsOptions
|
||||
options: RenderWithAtomsOptions,
|
||||
) => {
|
||||
return render(
|
||||
<HydrateAtomsWrapper initialValues={options.initialValues}>{component}</HydrateAtomsWrapper>
|
||||
<HydrateAtomsWrapper initialValues={options.initialValues}>{component}</HydrateAtomsWrapper>,
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ test('fire changeText event', () => {
|
||||
render(
|
||||
// MyComponent renders TextInput which has a placeholder 'Enter details'
|
||||
// and with `onChangeText` bound to handleChangeText
|
||||
<MyComponent handleChangeText={onEventMock} />
|
||||
<MyComponent handleChangeText={onEventMock} />,
|
||||
);
|
||||
|
||||
fireEvent(screen.getByPlaceholderText('change'), 'onChangeText', 'ab');
|
||||
@@ -46,7 +46,7 @@ const onBlurMock = jest.fn();
|
||||
render(
|
||||
<View>
|
||||
<TextInput placeholder="my placeholder" onBlur={onBlurMock} />
|
||||
</View>
|
||||
</View>,
|
||||
);
|
||||
|
||||
// you can omit the `on` prefix
|
||||
@@ -84,7 +84,7 @@ render(
|
||||
<TouchableOpacity onPress={onPressMock}>
|
||||
<Text>Press me</Text>
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
</View>,
|
||||
);
|
||||
|
||||
fireEvent.press(screen.getByText('Press me'), eventData);
|
||||
@@ -113,7 +113,7 @@ const CHANGE_TEXT = 'content';
|
||||
render(
|
||||
<View>
|
||||
<TextInput placeholder="Enter data" onChangeText={onChangeTextMock} />
|
||||
</View>
|
||||
</View>,
|
||||
);
|
||||
|
||||
fireEvent.changeText(screen.getByPlaceholderText('Enter data'), CHANGE_TEXT);
|
||||
@@ -145,7 +145,7 @@ const eventData = {
|
||||
render(
|
||||
<ScrollView onScroll={onScrollMock}>
|
||||
<Text>XD</Text>
|
||||
</ScrollView>
|
||||
</ScrollView>,
|
||||
);
|
||||
|
||||
fireEvent.scroll(screen.getByText('scroll-view'), eventData);
|
||||
|
||||
@@ -9,7 +9,7 @@ The `findBy*` queries are used to find elements that are not instantly available
|
||||
```tsx
|
||||
function waitFor<T>(
|
||||
expectation: () => T,
|
||||
options?: { timeout: number; interval: number }
|
||||
options?: { timeout: number; interval: number },
|
||||
): Promise<T>;
|
||||
```
|
||||
|
||||
@@ -109,7 +109,7 @@ If you receive warnings related to `act()` function consult our [Understanding A
|
||||
```ts
|
||||
function waitForElementToBeRemoved<T>(
|
||||
expectation: () => T,
|
||||
options?: { timeout: number; interval: number }
|
||||
options?: { timeout: number; interval: number },
|
||||
): Promise<T>;
|
||||
```
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
```ts
|
||||
function renderHook<Result, Props>(
|
||||
callback: (props?: Props) => Result,
|
||||
options?: RenderHookOptions<Props>
|
||||
options?: RenderHookOptions<Props>,
|
||||
): RenderHookResult<Result, Props>;
|
||||
```
|
||||
|
||||
|
||||
@@ -183,7 +183,7 @@ import { render, screen } from '@testing-library/react-native';
|
||||
render(
|
||||
<Pressable accessibilityRole="button" disabled>
|
||||
<Text>Hello</Text>
|
||||
</Pressable>
|
||||
</Pressable>,
|
||||
);
|
||||
const element = screen.getByRole('button');
|
||||
const element2 = screen.getByRole('button', { name: 'Hello' });
|
||||
@@ -398,13 +398,13 @@ render(<Text style={{ display: 'none' }}>Hidden from accessibility</Text>);
|
||||
expect(
|
||||
screen.queryByText('Hidden from accessibility', {
|
||||
includeHiddenElements: false,
|
||||
})
|
||||
}),
|
||||
).not.toBeOnTheScreen();
|
||||
|
||||
// Include hidden elements
|
||||
expect(screen.getByText('Hidden from accessibility')).toBeOnTheScreen();
|
||||
expect(
|
||||
screen.getByText('Hidden from accessibility', { includeHiddenElements: true })
|
||||
screen.getByText('Hidden from accessibility', { includeHiddenElements: true }),
|
||||
).toBeOnTheScreen();
|
||||
```
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ function findByText(text: TextMatch, options?: TextMatchOptions, waitForOptions?
|
||||
function findAllByText(
|
||||
text: TextMatch,
|
||||
options?: TextMatchOptions,
|
||||
waitForOptions?: WaitForOptions
|
||||
waitForOptions?: WaitForOptions,
|
||||
);
|
||||
```
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ In v1.14 we've introduced a feature allowing to match text when it's spread acro
|
||||
const { getByText } = render(
|
||||
<Text>
|
||||
Hello <Text>world</Text>
|
||||
</Text>
|
||||
</Text>,
|
||||
);
|
||||
getByText('Hello world'); // matches
|
||||
```
|
||||
|
||||
@@ -32,7 +32,7 @@ test('User can sign in with correct credentials', async () => {
|
||||
|
||||
// Follow-up assertions do not need to be async, as we already waited for sign in operation to complete
|
||||
expect(
|
||||
screen.queryByRole('header', { name: 'Sign in to Hello World App' })
|
||||
screen.queryByRole('header', { name: 'Sign in to Hello World App' }),
|
||||
).not.toBeOnTheScreen();
|
||||
expect(screen.queryByLabelText('Username')).not.toBeOnTheScreen();
|
||||
expect(screen.queryByLabelText('Password')).not.toBeOnTheScreen();
|
||||
@@ -87,7 +87,7 @@ function waitFor<T>(
|
||||
options?: {
|
||||
timeout: number;
|
||||
interval: number;
|
||||
}
|
||||
},
|
||||
): Promise<T>;
|
||||
```
|
||||
|
||||
@@ -111,7 +111,7 @@ function waitForElementToBeRemoved<T>(
|
||||
options?: {
|
||||
timeout: number;
|
||||
interval: number;
|
||||
}
|
||||
},
|
||||
): Promise<T> {}
|
||||
```
|
||||
|
||||
|
||||
@@ -16,12 +16,12 @@ interface RenderWithProvidersProps {
|
||||
|
||||
export function renderWithProviders<T>(
|
||||
ui: React.ReactElement<T>,
|
||||
options?: RenderWithProvidersProps
|
||||
options?: RenderWithProvidersProps,
|
||||
) {
|
||||
return render(
|
||||
<UserProvider.Provider value={options?.user ?? null}>
|
||||
<ThemeProvider.Provider value={options?.theme ?? 'light'}>{ui}</ThemeProvider.Provider>
|
||||
</UserProvider.Provider>
|
||||
</UserProvider.Provider>,
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
@@ -110,10 +110,10 @@ export interface RenderWithAtomsOptions {
|
||||
*/
|
||||
export const renderWithAtoms = <T,>(
|
||||
component: React.ReactElement,
|
||||
options: RenderWithAtomsOptions
|
||||
options: RenderWithAtomsOptions,
|
||||
) => {
|
||||
return render(
|
||||
<HydrateAtomsWrapper initialValues={options.initialValues}>{component}</HydrateAtomsWrapper>
|
||||
<HydrateAtomsWrapper initialValues={options.initialValues}>{component}</HydrateAtomsWrapper>,
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ test('fire changeText event', () => {
|
||||
render(
|
||||
// MyComponent renders TextInput which has a placeholder 'Enter details'
|
||||
// and with `onChangeText` bound to handleChangeText
|
||||
<MyComponent handleChangeText={onEventMock} />
|
||||
<MyComponent handleChangeText={onEventMock} />,
|
||||
);
|
||||
|
||||
fireEvent(screen.getByPlaceholderText('change'), 'onChangeText', 'ab');
|
||||
@@ -48,7 +48,7 @@ const onBlurMock = jest.fn();
|
||||
render(
|
||||
<View>
|
||||
<TextInput placeholder="my placeholder" onBlur={onBlurMock} />
|
||||
</View>
|
||||
</View>,
|
||||
);
|
||||
|
||||
// you can omit the `on` prefix
|
||||
@@ -89,7 +89,7 @@ render(
|
||||
<TouchableOpacity onPress={onPressMock}>
|
||||
<Text>Press me</Text>
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
</View>,
|
||||
);
|
||||
|
||||
fireEvent.press(screen.getByText('Press me'), eventData);
|
||||
@@ -121,7 +121,7 @@ const CHANGE_TEXT = 'content';
|
||||
render(
|
||||
<View>
|
||||
<TextInput placeholder="Enter data" onChangeText={onChangeTextMock} />
|
||||
</View>
|
||||
</View>,
|
||||
);
|
||||
|
||||
fireEvent.changeText(screen.getByPlaceholderText('Enter data'), CHANGE_TEXT);
|
||||
@@ -160,7 +160,7 @@ const eventData = {
|
||||
render(
|
||||
<ScrollView onScroll={onScrollMock}>
|
||||
<Text>XD</Text>
|
||||
</ScrollView>
|
||||
</ScrollView>,
|
||||
);
|
||||
|
||||
fireEvent.scroll(screen.getByText('scroll-view'), eventData);
|
||||
|
||||
@@ -9,7 +9,7 @@ The `findBy*` queries are used to find elements that are not instantly available
|
||||
```tsx
|
||||
function waitFor<T>(
|
||||
expectation: () => T,
|
||||
options?: { timeout: number; interval: number }
|
||||
options?: { timeout: number; interval: number },
|
||||
): Promise<T>;
|
||||
```
|
||||
|
||||
@@ -99,7 +99,7 @@ If you receive warnings related to `act()` function consult our [Understanding A
|
||||
```ts
|
||||
function waitForElementToBeRemoved<T>(
|
||||
expectation: () => T,
|
||||
options?: { timeout: number; interval: number }
|
||||
options?: { timeout: number; interval: number },
|
||||
): Promise<T>;
|
||||
```
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
```ts
|
||||
function renderHook<Result, Props>(
|
||||
hookFn: (props?: Props) => Result,
|
||||
options?: RenderHookOptions<Props>
|
||||
options?: RenderHookOptions<Props>,
|
||||
): RenderHookResult<Result, Props>;
|
||||
```
|
||||
|
||||
@@ -137,7 +137,7 @@ it('should use context value', () => {
|
||||
```ts
|
||||
async function renderHookAsync<Result, Props>(
|
||||
hookFn: (props?: Props) => Result,
|
||||
options?: RenderHookOptions<Props>
|
||||
options?: RenderHookOptions<Props>,
|
||||
): Promise<RenderHookAsyncResult<Result, Props>>;
|
||||
```
|
||||
|
||||
|
||||
@@ -180,7 +180,7 @@ import { render, screen } from '@testing-library/react-native';
|
||||
render(
|
||||
<Pressable accessibilityRole="button" disabled>
|
||||
<Text>Hello</Text>
|
||||
</Pressable>
|
||||
</Pressable>,
|
||||
);
|
||||
const element = screen.getByRole('button');
|
||||
const element2 = screen.getByRole('button', { name: 'Hello' });
|
||||
@@ -395,13 +395,13 @@ render(<Text style={{ display: 'none' }}>Hidden from accessibility</Text>);
|
||||
expect(
|
||||
screen.queryByText('Hidden from accessibility', {
|
||||
includeHiddenElements: false,
|
||||
})
|
||||
}),
|
||||
).not.toBeOnTheScreen();
|
||||
|
||||
// Include hidden elements
|
||||
expect(screen.getByText('Hidden from accessibility')).toBeOnTheScreen();
|
||||
expect(
|
||||
screen.getByText('Hidden from accessibility', { includeHiddenElements: true })
|
||||
screen.getByText('Hidden from accessibility', { includeHiddenElements: true }),
|
||||
).toBeOnTheScreen();
|
||||
```
|
||||
|
||||
|
||||
@@ -78,7 +78,7 @@ This API requires RNTL v13.3.0 or later.
|
||||
```tsx
|
||||
async function renderAsync(
|
||||
component: React.Element<any>,
|
||||
options?: RenderAsyncOptions
|
||||
options?: RenderAsyncOptions,
|
||||
): Promise<RenderAsyncResult>;
|
||||
```
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ function findByText(text: TextMatch, options?: TextMatchOptions, waitForOptions?
|
||||
function findAllByText(
|
||||
text: TextMatch,
|
||||
options?: TextMatchOptions,
|
||||
waitForOptions?: WaitForOptions
|
||||
waitForOptions?: WaitForOptions,
|
||||
);
|
||||
```
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ In v1.14 we've introduced a feature allowing to match text when it's spread acro
|
||||
const { getByText } = render(
|
||||
<Text>
|
||||
Hello <Text>world</Text>
|
||||
</Text>
|
||||
</Text>,
|
||||
);
|
||||
getByText('Hello world'); // matches
|
||||
```
|
||||
|
||||
@@ -33,7 +33,7 @@ test('User can sign in with correct credentials', async () => {
|
||||
|
||||
// Follow-up assertions do not need to be async, as we already waited for sign in operation to complete
|
||||
expect(
|
||||
screen.queryByRole('header', { name: 'Sign in to Hello World App' })
|
||||
screen.queryByRole('header', { name: 'Sign in to Hello World App' }),
|
||||
).not.toBeOnTheScreen();
|
||||
expect(screen.queryByLabelText('Username')).not.toBeOnTheScreen();
|
||||
expect(screen.queryByLabelText('Password')).not.toBeOnTheScreen();
|
||||
@@ -72,7 +72,7 @@ Each query has a default `timeout` value of 1000 ms and a default `interval` of
|
||||
const button = await screen.findByRole(
|
||||
'button',
|
||||
{ name: 'Start' },
|
||||
{ timeout: 1000, interval: 50 }
|
||||
{ timeout: 1000, interval: 50 },
|
||||
);
|
||||
```
|
||||
|
||||
@@ -92,7 +92,7 @@ function waitFor<T>(
|
||||
options?: {
|
||||
timeout: number;
|
||||
interval: number;
|
||||
}
|
||||
},
|
||||
): Promise<T>;
|
||||
```
|
||||
|
||||
@@ -116,7 +116,7 @@ function waitForElementToBeRemoved<T>(
|
||||
options?: {
|
||||
timeout: number;
|
||||
interval: number;
|
||||
}
|
||||
},
|
||||
): Promise<T> {}
|
||||
```
|
||||
|
||||
|
||||
@@ -16,12 +16,12 @@ interface RenderWithProvidersProps {
|
||||
|
||||
export async function renderWithProviders<T>(
|
||||
ui: React.ReactElement<T>,
|
||||
options?: RenderWithProvidersProps
|
||||
options?: RenderWithProvidersProps,
|
||||
) {
|
||||
return await render(
|
||||
<UserProvider.Provider value={options?.user ?? null}>
|
||||
<ThemeProvider.Provider value={options?.theme ?? 'light'}>{ui}</ThemeProvider.Provider>
|
||||
</UserProvider.Provider>
|
||||
</UserProvider.Provider>,
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
@@ -110,10 +110,10 @@ export interface RenderWithAtomsOptions {
|
||||
*/
|
||||
export async function renderWithAtoms<T>(
|
||||
component: React.ReactElement,
|
||||
options: RenderWithAtomsOptions
|
||||
options: RenderWithAtomsOptions,
|
||||
) {
|
||||
return await render(
|
||||
<HydrateAtomsWrapper initialValues={options.initialValues}>{component}</HydrateAtomsWrapper>
|
||||
<HydrateAtomsWrapper initialValues={options.initialValues}>{component}</HydrateAtomsWrapper>,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ test('fire changeText event', async () => {
|
||||
await render(
|
||||
// MyComponent renders TextInput which has a placeholder 'Enter details'
|
||||
// and with `onChangeText` bound to handleChangeText
|
||||
<MyComponent handleChangeText={onEventMock} />
|
||||
<MyComponent handleChangeText={onEventMock} />,
|
||||
);
|
||||
|
||||
await fireEvent(screen.getByPlaceholderText('change'), 'onChangeText', 'ab');
|
||||
@@ -49,7 +49,7 @@ const onBlurMock = jest.fn();
|
||||
await render(
|
||||
<View>
|
||||
<TextInput placeholder="my placeholder" onBlur={onBlurMock} />
|
||||
</View>
|
||||
</View>,
|
||||
);
|
||||
|
||||
// you can omit the `on` prefix
|
||||
@@ -90,7 +90,7 @@ await render(
|
||||
<TouchableOpacity onPress={onPressMock}>
|
||||
<Text>Press me</Text>
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
</View>,
|
||||
);
|
||||
|
||||
await fireEvent.press(screen.getByText('Press me'), eventData);
|
||||
@@ -122,7 +122,7 @@ const CHANGE_TEXT = 'content';
|
||||
await render(
|
||||
<View>
|
||||
<TextInput placeholder="Enter data" onChangeText={onChangeTextMock} />
|
||||
</View>
|
||||
</View>,
|
||||
);
|
||||
|
||||
await fireEvent.changeText(screen.getByPlaceholderText('Enter data'), CHANGE_TEXT);
|
||||
@@ -161,7 +161,7 @@ const eventData = {
|
||||
await render(
|
||||
<ScrollView testID="scroll-view" onScroll={onScrollMock}>
|
||||
<Text>Content</Text>
|
||||
</ScrollView>
|
||||
</ScrollView>,
|
||||
);
|
||||
|
||||
await fireEvent.scroll(screen.getByTestId('scroll-view'), eventData);
|
||||
|
||||
@@ -13,7 +13,7 @@ function waitFor<T>(
|
||||
timeout?: number;
|
||||
interval?: number;
|
||||
onTimeout?: (error: Error) => Error;
|
||||
}
|
||||
},
|
||||
): Promise<T>;
|
||||
```
|
||||
|
||||
@@ -93,7 +93,7 @@ await waitFor(
|
||||
() => {
|
||||
expect(someFunction).toHaveBeenCalledWith();
|
||||
},
|
||||
{ timeout: 10000 }
|
||||
{ timeout: 10000 },
|
||||
);
|
||||
```
|
||||
|
||||
@@ -116,7 +116,7 @@ function waitForElementToBeRemoved<T>(
|
||||
timeout?: number;
|
||||
interval?: number;
|
||||
onTimeout?: (error: Error) => Error;
|
||||
}
|
||||
},
|
||||
): Promise<T>;
|
||||
```
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
```ts
|
||||
async function renderHook<Result, Props>(
|
||||
hookFn: (props: Props) => Result,
|
||||
options?: RenderHookOptions<Props>
|
||||
options?: RenderHookOptions<Props>,
|
||||
): Promise<RenderHookResult<Result, Props>>;
|
||||
```
|
||||
|
||||
|
||||
@@ -183,7 +183,7 @@ import { render, screen } from '@testing-library/react-native';
|
||||
await render(
|
||||
<Pressable accessibilityRole="button" disabled>
|
||||
<Text>Hello</Text>
|
||||
</Pressable>
|
||||
</Pressable>,
|
||||
);
|
||||
const element = screen.getByRole('button');
|
||||
const element2 = screen.getByRole('button', { name: 'Hello' });
|
||||
@@ -399,13 +399,13 @@ await render(<Text style={{ display: 'none' }}>Hidden from accessibility</Text>)
|
||||
expect(
|
||||
screen.queryByText('Hidden from accessibility', {
|
||||
includeHiddenElements: false,
|
||||
})
|
||||
}),
|
||||
).not.toBeOnTheScreen();
|
||||
|
||||
// Include hidden elements
|
||||
expect(screen.getByText('Hidden from accessibility')).toBeOnTheScreen();
|
||||
expect(
|
||||
screen.getByText('Hidden from accessibility', { includeHiddenElements: true })
|
||||
screen.getByText('Hidden from accessibility', { includeHiddenElements: true }),
|
||||
).toBeOnTheScreen();
|
||||
```
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
```ts
|
||||
async function render<T>(
|
||||
element: React.ReactElement<T>,
|
||||
options?: RenderOptions
|
||||
options?: RenderOptions,
|
||||
): Promise<RenderResult>;
|
||||
```
|
||||
|
||||
|
||||
@@ -186,7 +186,7 @@ test('example', async () => {
|
||||
await render(
|
||||
<View testID="root-view">
|
||||
<Text>Hello</Text>
|
||||
</View>
|
||||
</View>,
|
||||
);
|
||||
// root is the View element you rendered
|
||||
expect(screen.root.props.testID).toBe('root-view');
|
||||
|
||||
@@ -2693,6 +2693,62 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@oxfmt/darwin-arm64@npm:0.26.0":
|
||||
version: 0.26.0
|
||||
resolution: "@oxfmt/darwin-arm64@npm:0.26.0"
|
||||
conditions: os=darwin & cpu=arm64
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@oxfmt/darwin-x64@npm:0.26.0":
|
||||
version: 0.26.0
|
||||
resolution: "@oxfmt/darwin-x64@npm:0.26.0"
|
||||
conditions: os=darwin & cpu=x64
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@oxfmt/linux-arm64-gnu@npm:0.26.0":
|
||||
version: 0.26.0
|
||||
resolution: "@oxfmt/linux-arm64-gnu@npm:0.26.0"
|
||||
conditions: os=linux & cpu=arm64 & libc=glibc
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@oxfmt/linux-arm64-musl@npm:0.26.0":
|
||||
version: 0.26.0
|
||||
resolution: "@oxfmt/linux-arm64-musl@npm:0.26.0"
|
||||
conditions: os=linux & cpu=arm64 & libc=musl
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@oxfmt/linux-x64-gnu@npm:0.26.0":
|
||||
version: 0.26.0
|
||||
resolution: "@oxfmt/linux-x64-gnu@npm:0.26.0"
|
||||
conditions: os=linux & cpu=x64 & libc=glibc
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@oxfmt/linux-x64-musl@npm:0.26.0":
|
||||
version: 0.26.0
|
||||
resolution: "@oxfmt/linux-x64-musl@npm:0.26.0"
|
||||
conditions: os=linux & cpu=x64 & libc=musl
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@oxfmt/win32-arm64@npm:0.26.0":
|
||||
version: 0.26.0
|
||||
resolution: "@oxfmt/win32-arm64@npm:0.26.0"
|
||||
conditions: os=win32 & cpu=arm64
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@oxfmt/win32-x64@npm:0.26.0":
|
||||
version: 0.26.0
|
||||
resolution: "@oxfmt/win32-x64@npm:0.26.0"
|
||||
conditions: os=win32 & cpu=x64
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@phun-ky/typeof@npm:2.0.3":
|
||||
version: 2.0.3
|
||||
resolution: "@phun-ky/typeof@npm:2.0.3"
|
||||
@@ -3030,6 +3086,7 @@ __metadata:
|
||||
eslint-plugin-simple-import-sort: "npm:^12.1.1"
|
||||
jest: "npm:^30.2.0"
|
||||
jest-matcher-utils: "npm:^30.2.0"
|
||||
oxfmt: "npm:^0.26.0"
|
||||
picocolors: "npm:^1.1.1"
|
||||
prettier: "npm:^3.6.2"
|
||||
pretty-format: "npm:^30.2.0"
|
||||
@@ -8830,6 +8887,42 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"oxfmt@npm:^0.26.0":
|
||||
version: 0.26.0
|
||||
resolution: "oxfmt@npm:0.26.0"
|
||||
dependencies:
|
||||
"@oxfmt/darwin-arm64": "npm:0.26.0"
|
||||
"@oxfmt/darwin-x64": "npm:0.26.0"
|
||||
"@oxfmt/linux-arm64-gnu": "npm:0.26.0"
|
||||
"@oxfmt/linux-arm64-musl": "npm:0.26.0"
|
||||
"@oxfmt/linux-x64-gnu": "npm:0.26.0"
|
||||
"@oxfmt/linux-x64-musl": "npm:0.26.0"
|
||||
"@oxfmt/win32-arm64": "npm:0.26.0"
|
||||
"@oxfmt/win32-x64": "npm:0.26.0"
|
||||
tinypool: "npm:2.0.0"
|
||||
dependenciesMeta:
|
||||
"@oxfmt/darwin-arm64":
|
||||
optional: true
|
||||
"@oxfmt/darwin-x64":
|
||||
optional: true
|
||||
"@oxfmt/linux-arm64-gnu":
|
||||
optional: true
|
||||
"@oxfmt/linux-arm64-musl":
|
||||
optional: true
|
||||
"@oxfmt/linux-x64-gnu":
|
||||
optional: true
|
||||
"@oxfmt/linux-x64-musl":
|
||||
optional: true
|
||||
"@oxfmt/win32-arm64":
|
||||
optional: true
|
||||
"@oxfmt/win32-x64":
|
||||
optional: true
|
||||
bin:
|
||||
oxfmt: bin/oxfmt
|
||||
checksum: 10c0/7e782fdd313883fb51998724ebe4402423a6d67348378402ddf6b5d8751fc891d1538d1d5289a524c988b29678e29ba94924655cdf252a90c68b6b24a8b02a92
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"p-limit@npm:^2.0.0, p-limit@npm:^2.2.0":
|
||||
version: 2.3.0
|
||||
resolution: "p-limit@npm:2.3.0"
|
||||
@@ -10476,6 +10569,13 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"tinypool@npm:2.0.0":
|
||||
version: 2.0.0
|
||||
resolution: "tinypool@npm:2.0.0"
|
||||
checksum: 10c0/3888cc668cdbb1bc85e1b58587897501254ffc5de52cf4e0d30936869922a4eaf2f085ce10562122df3eb7536cbf3d29ecc2faba37656933649d1d2f5bc9bff7
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"tmpl@npm:1.0.5":
|
||||
version: 1.0.5
|
||||
resolution: "tmpl@npm:1.0.5"
|
||||
|
||||
Reference in New Issue
Block a user