Skip to content

Commit 4f7dd48

Browse files
docs: table of contents for Queries and API pages (#980)
* docs: add toc for APIs * docs: add toc for Queries
1 parent 16bb83c commit 4f7dd48

File tree

2 files changed

+84
-23
lines changed

2 files changed

+84
-23
lines changed

website/docs/API.md

Lines changed: 55 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,34 @@ id: api
33
title: API
44
---
55

6+
### Table of contents:
7+
8+
- [`render`](#render)
9+
- [`update`](#update)
10+
- [`unmount`](#unmount)
11+
- [`debug`](#debug)
12+
- [`toJSON`](#tojson)
13+
- [`container`](#container)
14+
- [`cleanup`](#cleanup)
15+
- [`fireEvent`](#fireevent)
16+
- [`fireEvent[eventName]`](#fireeventeventname)
17+
- [`fireEvent.press`](#fireeventpress)
18+
- [`fireEvent.changeText`](#fireeventchangetext)
19+
- [`fireEvent.scroll`](#fireeventscroll)
20+
- [`waitFor`](#waitfor)
21+
- [`waitForElementToBeRemoved`](#waitforelementtoberemoved)
22+
- [`within, getQueriesForElement`](#within-getqueriesforelement)
23+
- [`query` APIs](#query-apis)
24+
- [`queryAll` APIs](#queryall-apis)
25+
- [`act`](#act)
26+
- [`renderHook`](#renderhook)
27+
- [`callback`](#callback)
28+
- [`options`](#options-optional)
29+
- [`RenderHookResult` object](#renderhookresult-object)
30+
- [`result`](#result)
31+
- [`rerender`](#rerender)
32+
- [`unmount`](#unmount-1)
33+
634
This page gathers public API of React Native Testing Library along with usage examples.
735

836
## `render`
@@ -225,7 +253,11 @@ fireEvent[eventName](element: ReactTestInstance, ...data: Array<any>): void
225253

226254
Convenience methods for common events like: `press`, `changeText`, `scroll`.
227255

228-
### `fireEvent.press: (element: ReactTestInstance, ...data: Array<any>) => void`
256+
### `fireEvent.press`
257+
258+
```
259+
fireEvent.press: (element: ReactTestInstance, ...data: Array<any>) => void
260+
```
229261

230262
Invokes `press` event handler on the element or parent element in the tree.
231263

@@ -253,7 +285,11 @@ fireEvent.press(getByText('Press me'), eventData);
253285
expect(onPressMock).toHaveBeenCalledWith(eventData);
254286
```
255287

256-
### `fireEvent.changeText: (element: ReactTestInstance, ...data: Array<any>) => void`
288+
### `fireEvent.changeText`
289+
290+
```
291+
fireEvent.changeText: (element: ReactTestInstance, ...data: Array<any>) => void
292+
```
257293

258294
Invokes `changeText` event handler on the element or parent element in the tree.
259295

@@ -273,7 +309,11 @@ const { getByPlaceholderText } = render(
273309
fireEvent.changeText(getByPlaceholderText('Enter data'), CHANGE_TEXT);
274310
```
275311

276-
### `fireEvent.scroll: (element: ReactTestInstance, ...data: Array<any>) => void`
312+
### `fireEvent.scroll`
313+
314+
```
315+
fireEvent.scroll: (element: ReactTestInstance, ...data: Array<any>) => void
316+
```
277317

278318
Invokes `scroll` event handler on the element or parent element in the tree.
279319

@@ -519,40 +559,34 @@ A `RenderHookOptions<Props>` object to modify the execution of the `callback` fu
519559

520560
#### `initialProps`
521561

522-
The initial values to pass as `props` to the `callback` function of `renderHook`. The `Props` type is determined by the type passed to or inferred by the `renderHook` call.
562+
The initial values to pass as `props` to the `callback` function of `renderHook`. The `Props` type is determined by the type passed to or inferred by the `renderHook` call.
523563

524564
#### `wrapper`
525565

526566
A React component to wrap the test component in when rendering. This is usually used to add context providers from `React.createContext` for the hook to access with `useContext`.
527567

528-
### `RenderHookResult<Result, Props>` object
568+
### `RenderHookResult` object
569+
570+
```ts
571+
interface RenderHookResult<Result, Props> {
572+
result: { current: Result };
573+
rerender: (props: Props) => void;
574+
unmount: () => void;
575+
}
576+
```
529577

530578
The `renderHook` function returns an object that has the following properties:
531579

532580
#### `result`
533581

534-
```jsx
535-
{
536-
current: Result
537-
}
538-
```
539-
540-
The `current` value of the `result` will reflect the latest of whatever is returned from the `callback` passed to `renderHook`. The `Result` type is determined by the type passed to or inferred by the `renderHook` call.
582+
The `current` value of the `result` will reflect the latest of whatever is returned from the `callback` passed to `renderHook`. The `Result` type is determined by the type passed to or inferred by the `renderHook` call.
541583

542584
#### `rerender`
543585

544-
```ts
545-
function rerender(newProps?: Props): void;
546-
```
547-
548-
A function to rerender the test component, causing any hooks to be recalculated. If `newProps` are passed, they will replace the `callback` function's `initialProps` for subsequent rerenders. The `Props` type is determined by the type passed to or inferred by the `renderHook` call.
586+
A function to rerender the test component, causing any hooks to be recalculated. If `newProps` are passed, they will replace the `callback` function's `initialProps` for subsequent rerenders. The `Props` type is determined by the type passed to or inferred by the `renderHook` call.
549587

550588
#### `unmount`
551589

552-
```ts
553-
function unmount(): void;
554-
```
555-
556590
A function to unmount the test component. This is commonly used to trigger cleanup effects for `useEffect` hooks.
557591

558592
### Examples

website/docs/Queries.md

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,33 @@ id: api-queries
33
title: Queries
44
---
55

6+
### Table of contents:
7+
8+
- [Variants](#variants)
9+
- [`getBy`](#getby)
10+
- [`getAllBy`](#getallby)
11+
- [`queryBy`](#queryby)
12+
- [`queryAllBy`](#queryallby)
13+
- [`findBy`](#findby)
14+
- [`findAllBy`](#findallby)
15+
- [Queries](#queries)
16+
- [`options`](#options)
17+
- [`ByText`](#bytext)
18+
- [`ByPlaceholderText`](#byplaceholdertext)
19+
- [`ByDisplayValue`](#bydisplayvalue)
20+
- [`ByTestId`](#bytestid)
21+
- [`ByLabelText`](#bylabeltext)
22+
- [`ByHintText`, `ByA11yHint`, `ByAccessibilityHint`](#byhinttext-bya11yhint-byaccessibilityhint)
23+
- [`ByA11yStates`, `ByAccessibilityStates`](#bya11ystates-byaccessibilitystates)
24+
- [`ByRole`](#byrole)
25+
- [`ByA11yState`, `ByAccessibilityState`](#bya11ystate-byaccessibilitystate)
26+
- [`ByA11Value`, `ByAccessibilityValue`](#bya11value-byaccessibilityvalue)
27+
- [`TextMatch`](#textmatch)
28+
- [Examples](#examples)
29+
- [Precision](#precision)
30+
- [Normalization](#normalization)
31+
- [Unit testing helpers](#unit-testing-helpers)
32+
633
## Variants
734

835
> `getBy` queries are shown by default in the [query documentation](#queries)
@@ -55,7 +82,7 @@ type ReactTestInstance = {
5582

5683
### Options
5784

58-
Query first argument can be a **string** or a **regex**. Some queries accept optional argument which change string matching behaviour. See [TextMatch](#textmatch) for more info.
85+
Usually query first argument can be a **string** or a **regex**. Some queries accept optional argument which change string matching behaviour. See [TextMatch](#textmatch) for more info.
5986

6087
### `ByText`
6188

@@ -128,7 +155,7 @@ const { getByLabelText } = render(<MyComponent />);
128155
const element = getByLabelText('my-label');
129156
```
130157

131-
### `ByA11yHint`, `ByAccessibilityHint`, `ByHintText`
158+
### `ByHintText`, `ByA11yHint`, `ByAccessibilityHint`
132159

133160
> getByA11yHint, getAllByA11yHint, queryByA11yHint, queryAllByA11yHint, findByA11yHint, findAllByA11yHint
134161
> getByAccessibilityHint, getAllByAccessibilityHint, queryByAccessibilityHint, queryAllByAccessibilityHint, findByAccessibilityHint, findAllByAccessibilityHint

0 commit comments

Comments
 (0)