Skip to content

Commit 75efa72

Browse files
committed
docs: api overview page
1 parent 70ee4fd commit 75efa72

File tree

8 files changed

+31
-14
lines changed

8 files changed

+31
-14
lines changed

website/docs/API.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
id: api
3+
title: API Overview
4+
---
5+
6+
React Native Testing Library consists of following APIs:
7+
8+
- [`render` function](render) - render your UI components for testing purposes
9+
- [`screen` object](screen) - access rendered UI:
10+
- [Queries](queries) - find relevant components by various predicates: role, text, test ids, etc
11+
- Lifecycle methods: [`rerender`](screen#rerender), [`unmount`](screen#unmount)
12+
- Helpers: [`debug`](screen#debug), [`toJSON`](screen#tojson), [`root`](screen#root)
13+
- [Jest matchers](jest-matchers) - validate assumptions about your UI
14+
- [User Event](user-event) - simulate common user interactions like [`press`](user-event#press) or [`type`](user-event#type) in a realistic way
15+
- [Fire Event](fire-event) - simulate any component event in a simplified way
16+
- [Other APIs](other):
17+
- [Async utils](other#async-utilities): `findBy*` queries, `wait`, `waitForElementToBeRemoved`
18+
- [Configuration](other#configuration): `configure`, `resetToDefaults`
19+
- [Accessibility](other#accessibility): `isHiddenFromAccessibility`
20+
- [Other](other#other-helpers): `within`, `act`, `cleanup`

website/docs/FireEvent.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ title: Fire Event
77
function fireEvent(
88
element: ReactTestInstance,
99
eventName: string,
10-
...data: Array<any>
11-
): void
10+
...data: unknown[],
11+
): void;
1212
```
1313

1414
:::note
@@ -163,4 +163,3 @@ fireEvent.scroll(screen.getByText('scroll-view'), eventData);
163163
Prefer using [`user.scrollTo`](./UserEvent.md#scrollto) over `fireEvent.scroll` for `ScrollView`, `FlatList`, and `SectionList` components. User Event provides a more realistic event simulation based on React Native runtime behavior.
164164

165165
:::
166-

website/docs/OtherAPIs.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,7 @@ $ RNTL_SKIP_AUTO_DETECT_FAKE_TIMERS=true jest
199199
### `isHiddenFromAccessibility`
200200

201201
```ts
202-
function isHiddenFromAccessibility(
203-
element: ReactTestInstance | null
204-
): boolean {}
202+
function isHiddenFromAccessibility(element: ReactTestInstance | null): boolean {}
205203
```
206204

207205
Also available as `isInaccessible()` alias for React Testing Library compatibility.
@@ -226,7 +224,7 @@ Specifying `accessible={false}`, `accessiblityRole="none"`, or `importantForAcce
226224

227225
## Other helpers
228226

229-
### `within`, `getQueriesForElement`
227+
### `within`, `getQueriesForElement` {#within}
230228

231229
```jsx
232230
function within(element: ReactTestInstance): Queries {}
@@ -298,4 +296,4 @@ describe('when logged in', () => {
298296
});
299297
```
300298

301-
Failing to call `cleanup` when you've called `render` could result in a memory leak and tests which are not "idempotent" (which can lead to difficult to debug errors in your tests).
299+
Failing to call `cleanup` when you've called `render` could result in a memory leak and tests which are not "idempotent" (which can lead to difficult to debug errors in your tests).

website/docs/Queries.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
id: queries
3-
title: Queries API
3+
title: Queries
44
---
55

66
Queries are one of the main building blocks for the React Native Testing Library. They enable you to find relevant elements in the element tree, which represents the your application's user interface when running under tests.

website/docs/Render.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
id: render
3-
title: Render API
3+
title: Render function
44
---
55

66
```jsx

website/docs/Screen.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
id: screen
3-
title: Screen API
3+
title: Screen object
44
---
55

66
```ts
@@ -31,7 +31,7 @@ See [Queries](./Queries.md) for a complete list.
3131
import { render, screen } from '@testing-library/react-native';
3232

3333
render(<MyComponent />);
34-
const buttonStart = screen.getByRole('button', { name: 'start' })
34+
const buttonStart = screen.getByRole('button', { name: 'start' });
3535
```
3636

3737
### `rerender`
@@ -154,4 +154,3 @@ Returns the rendered [composite root element](testing-env#host-and-composite-com
154154
:::note
155155
This API has been previously named `container` for compatibility with [React Testing Library](https://testing-library.com/docs/react-testing-library/other#container-1). However, despite the same name, the actual behavior has been significantly different; hence, we decided to change the name to `UNSAFE_root`.
156156
:::
157-

website/docs/UserEvent.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
id: user-event
3-
title: User Event
3+
title: User Event interactions
44
---
55

66
:::note

website/sidebars.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ module.exports = {
22
docs: {
33
Introduction: ['getting-started'],
44
'API Reference': [
5+
'api',
56
'render',
67
'screen',
78
'queries',

0 commit comments

Comments
 (0)