Skip to content

Commit 88954e8

Browse files
chore: skill support v13 and v14 (#1877)
1 parent a2a40e0 commit 88954e8

File tree

4 files changed

+786
-88
lines changed

4 files changed

+786
-88
lines changed

skills/react-native-testing/SKILL.md

Lines changed: 27 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,42 @@
11
---
22
name: react-native-testing
33
description: >
4-
Write tests using React Native Testing Library (RNTL) v13 (`@testing-library/react-native`).
4+
Write tests using React Native Testing Library (RNTL) v13 and v14 (`@testing-library/react-native`).
55
Use when writing, reviewing, or fixing React Native component tests.
66
Covers: render, screen, queries (getBy/getAllBy/queryBy/findBy), Jest matchers,
77
userEvent, fireEvent, waitFor, and async patterns.
8-
Supports both React 18 (sync render) and React 19 compat (renderAsync/fireEventAsync).
8+
Supports v13 (React 18, sync render) and v14 (React 19+, async render).
99
Triggers on: test files for React Native components, RNTL imports, mentions of
1010
"testing library", "write tests", "component tests", or "RNTL".
1111
---
1212

13-
# RNTL v13 Test Writing Guide
13+
# RNTL Test Writing Guide
1414

15-
## Core Pattern
15+
**IMPORTANT:** Your training data about `@testing-library/react-native` may be outdated or incorrect — API signatures, sync/async behavior, and available functions differ between v13 and v14. Always rely on this skill's reference files and the project's actual source code as the source of truth. Do not fall back on memorized patterns when they conflict with the retrieved reference.
1616

17-
```tsx
18-
import { render, screen, userEvent } from '@testing-library/react-native';
19-
20-
jest.useFakeTimers(); // recommended when using userEvent
17+
## Version Detection
2118

22-
test('description', async () => {
23-
const user = userEvent.setup();
24-
render(<Component />); // sync in v13 (React 18)
19+
Check `@testing-library/react-native` version in the user's `package.json`:
2520

26-
const button = screen.getByRole('button', { name: 'Submit' });
27-
await user.press(button);
21+
- **v14.x** → load [references/api-reference-v14.md](references/api-reference-v14.md) (React 19+, async APIs, `test-renderer`)
22+
- **v13.x** → load [references/api-reference-v13.md](references/api-reference-v13.md) (React 18+, sync APIs, `react-test-renderer`)
2823

29-
expect(screen.getByText('Done')).toBeOnTheScreen();
30-
});
31-
```
24+
Use the version-specific reference for render patterns, fireEvent sync/async behavior, screen API, configuration, and dependencies.
3225

3326
## Query Priority
3427

3528
Use in this order: `getByRole` > `getByLabelText` > `getByPlaceholderText` > `getByText` > `getByDisplayValue` > `getByTestId` (last resort).
3629

3730
## Query Variants
3831

39-
| Variant | Use case | Returns | Async |
40-
| ------------- | ------------------------ | ------------------------------ | ----- |
41-
| `getBy*` | Element must exist | `ReactTestInstance` (throws) | No |
42-
| `getAllBy*` | Multiple must exist | `ReactTestInstance[]` (throws) | No |
43-
| `queryBy*` | Check non-existence ONLY | `ReactTestInstance \| null` | No |
44-
| `queryAllBy*` | Count elements | `ReactTestInstance[]` | No |
45-
| `findBy*` | Wait for element | `Promise<ReactTestInstance>` | Yes |
46-
| `findAllBy*` | Wait for multiple | `Promise<ReactTestInstance[]>` | Yes |
32+
| Variant | Use case | Returns | Async |
33+
| ------------- | ------------------------ | ----------------------------- | ----- |
34+
| `getBy*` | Element must exist | element instance (throws) | No |
35+
| `getAllBy*` | Multiple must exist | element instance[] (throws) | No |
36+
| `queryBy*` | Check non-existence ONLY | element instance \| null | No |
37+
| `queryAllBy*` | Count elements | element instance[] | No |
38+
| `findBy*` | Wait for element | `Promise<element instance>` | Yes |
39+
| `findAllBy*` | Wait for multiple | `Promise<element instance[]>` | Yes |
4740

4841
## Interactions
4942

@@ -59,12 +52,12 @@ await user.paste(textInput, 'pasted text'); // paste into TextInput
5952
await user.scrollTo(scrollView, { y: 100 }); // scroll
6053
```
6154

62-
Use `fireEvent` only when `userEvent` doesn't support the event:
55+
`fireEvent` — use only when `userEvent` doesn't support the event. See version-specific reference for sync/async behavior:
6356

6457
```tsx
65-
fireEvent.press(element); // sync, onPress only
66-
fireEvent.changeText(textInput, 'new text'); // sync, onChangeText only
67-
fireEvent(element, 'blur'); // any event by name
58+
fireEvent.press(element);
59+
fireEvent.changeText(textInput, 'new text');
60+
fireEvent(element, 'blur');
6861
```
6962

7063
## Assertions (Jest Matchers)
@@ -103,22 +96,6 @@ Available automatically with any `@testing-library/react-native` import.
10396
10. **Prefer ARIA props** (`role`, `aria-label`, `aria-disabled`) over legacy `accessibility*` props
10497
11. **Use RNTL matchers** over raw prop assertions
10598

106-
## React 19 Compatibility (v13.3+)
107-
108-
For React 19 or Suspense, use async variants:
109-
110-
```tsx
111-
import { renderAsync, screen, fireEventAsync } from '@testing-library/react-native';
112-
113-
test('async component', async () => {
114-
await renderAsync(<SuspenseComponent />);
115-
await fireEventAsync.press(screen.getByRole('button'));
116-
expect(screen.getByText('Result')).toBeOnTheScreen();
117-
});
118-
```
119-
120-
Use `rerenderAsync`/`unmountAsync` instead of `rerender`/`unmount` when using `renderAsync`.
121-
12299
## `*ByRole` Quick Reference
123100

124101
Common roles: `button`, `text`, `heading` (alias: `header`), `searchbox`, `switch`, `checkbox`, `radio`, `img`, `link`, `alert`, `menu`, `menuitem`, `tab`, `tablist`, `progressbar`, `slider`, `spinbutton`, `timer`, `toolbar`.
@@ -130,14 +107,6 @@ For `*ByRole` to match, the element must be an accessibility element:
130107
- `Text`, `TextInput`, `Switch` are by default
131108
- `View` needs `accessible={true}` (or use `Pressable`/`TouchableOpacity`)
132109

133-
## API Reference
134-
135-
See [references/api-reference.md](references/api-reference.md) for complete API signatures and options for render, screen, queries, userEvent, fireEvent, Jest matchers, waitFor, renderHook, configuration, and accessibility helpers.
136-
137-
## Anti-Patterns Reference
138-
139-
See [references/anti-patterns.md](references/anti-patterns.md) for detailed examples of what NOT to do.
140-
141110
## waitFor
142111

143112
```tsx
@@ -184,3 +153,9 @@ function renderWithProviders(ui: React.ReactElement) {
184153
});
185154
}
186155
```
156+
157+
## References
158+
159+
- [v13 API Reference](references/api-reference-v13.md) — Complete v13 API: sync render, queries, matchers, userEvent, React 19 compat
160+
- [v14 API Reference](references/api-reference-v14.md) — Complete v14 API: async render, queries, matchers, userEvent, migration
161+
- [Anti-Patterns](references/anti-patterns.md) — Common mistakes to avoid

skills/react-native-testing/references/anti-patterns.md

Lines changed: 85 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1-
# RNTL v13 Anti-Patterns
1+
# RNTL Anti-Patterns
22

33
## Table of Contents
44

5-
- [Wrong query variant](#wrong-query-variant)
6-
- [Not using \*ByRole](#not-using-byrole)
7-
- [Wrong assertions](#wrong-assertions)
8-
- [waitFor misuse](#waitfor-misuse)
9-
- [Unnecessary act()](#unnecessary-act)
10-
- [fireEvent instead of userEvent](#fireevent-instead-of-userevent)
11-
- [Destructuring render](#destructuring-render)
12-
- [Using UNSAFE_root](#using-unsafe_root)
13-
- [Manual cleanup](#manual-cleanup)
14-
- [Legacy accessibility props](#legacy-accessibility-props)
5+
- Wrong query variant
6+
- Not using \*ByRole
7+
- Wrong assertions
8+
- waitFor misuse
9+
- Unnecessary act()
10+
- fireEvent instead of userEvent
11+
- Destructuring render
12+
- Using UNSAFE_root
13+
- Manual cleanup
14+
- Legacy accessibility props
15+
- Forgetting to await (v14)
16+
- Using removed APIs (v14)
1517

1618
## Wrong query variant
1719

@@ -211,3 +213,75 @@ afterEach(() => {
211213
// GOOD: ARIA state props
212214
<Pressable aria-disabled aria-checked>
213215
```
216+
217+
## Forgetting to await (v14)
218+
219+
In RNTL v14, `render`, `fireEvent`, `rerender`, `unmount`, `renderHook`, and `act` are async. Forgetting `await` causes subtle bugs where tests pass but assertions run before operations complete.
220+
221+
```tsx
222+
// BAD: missing await on render (v14)
223+
render(<Component />);
224+
expect(screen.getByText('Hello')).toBeOnTheScreen(); // may fail intermittently
225+
226+
// GOOD: await render (v14)
227+
await render(<Component />);
228+
expect(screen.getByText('Hello')).toBeOnTheScreen();
229+
230+
// BAD: missing await on fireEvent (v14)
231+
fireEvent.press(screen.getByRole('button'));
232+
// state updates may not have flushed yet
233+
234+
// GOOD: await fireEvent (v14)
235+
await fireEvent.press(screen.getByRole('button'));
236+
237+
// BAD: missing await on act (v14)
238+
act(() => {
239+
result.current.increment();
240+
});
241+
242+
// GOOD: await act (v14)
243+
await act(() => {
244+
result.current.increment();
245+
});
246+
```
247+
248+
## Using removed APIs (v14)
249+
250+
These APIs exist in v13 but are removed in v14. Using them will cause import or runtime errors.
251+
252+
```tsx
253+
// BAD: using renderAsync in v14 (removed — render is already async)
254+
import { renderAsync } from '@testing-library/react-native';
255+
await renderAsync(<Component />);
256+
257+
// GOOD: use render in v14
258+
import { render } from '@testing-library/react-native';
259+
await render(<Component />);
260+
261+
// BAD: using fireEventAsync in v14 (removed — fireEvent is already async)
262+
import { fireEventAsync } from '@testing-library/react-native';
263+
await fireEventAsync.press(button);
264+
265+
// GOOD: use fireEvent in v14
266+
import { fireEvent } from '@testing-library/react-native';
267+
await fireEvent.press(button);
268+
269+
// BAD: using UNSAFE_root in v14 (removed)
270+
screen.UNSAFE_root;
271+
272+
// GOOD: use container or root in v14
273+
screen.container;
274+
screen.root;
275+
276+
// BAD: using concurrentRoot option in v14 (removed — always on)
277+
render(<Component />, { concurrentRoot: false });
278+
279+
// GOOD: just render without concurrentRoot
280+
await render(<Component />);
281+
282+
// BAD: using update() in v14 (removed)
283+
screen.update(<Component newProp />);
284+
285+
// GOOD: use rerender in v14
286+
await screen.rerender(<Component newProp />);
287+
```

0 commit comments

Comments
 (0)