|
1 |
| -import * as React from 'react'; |
2 |
| -import { View, Text, Pressable } from 'react-native'; |
3 |
| -import { screen, fireEvent } from '@testing-library/react-native'; |
| 1 | +import React from 'react'; |
| 2 | +import { jest, test } from '@jest/globals'; |
| 3 | +import { fireEvent, screen } from '@testing-library/react-native'; |
4 | 4 | import { measureRenders } from 'reassure';
|
5 |
| -import { SlowList } from './SlowList'; |
| 5 | +import { AsyncComponent } from './AsyncComponent'; |
6 | 6 |
|
7 |
| -jest.setTimeout(60_000); |
| 7 | +jest.setTimeout(600_000); |
8 | 8 |
|
9 |
| -const AsyncComponent = () => { |
10 |
| - const [count, setCount] = React.useState(0); |
| 9 | +test('RN Expo - AsyncComponent 10 runs', async () => { |
| 10 | + const scenario = async () => { |
| 11 | + const button = screen.getByText('Action'); |
11 | 12 |
|
12 |
| - const handlePress = () => { |
13 |
| - setTimeout(() => setCount((c) => c + 1), 10); |
| 13 | + fireEvent.press(button); |
| 14 | + fireEvent.press(button); |
| 15 | + await screen.findByText('Count: 2'); |
14 | 16 | };
|
15 | 17 |
|
16 |
| - return ( |
17 |
| - <View> |
18 |
| - <Pressable accessibilityRole="button" onPress={handlePress}> |
19 |
| - <Text>Action</Text> |
20 |
| - </Pressable> |
21 |
| - |
22 |
| - <Text>Count: {count}</Text> |
23 |
| - |
24 |
| - <SlowList count={200} /> |
25 |
| - </View> |
26 |
| - ); |
27 |
| -}; |
| 18 | + await measureRenders(<AsyncComponent />, { scenario, runs: 10 }); |
| 19 | +}); |
28 | 20 |
|
29 |
| -test('Async Component', async () => { |
| 21 | +test('RN Expo - AsyncComponent 50 runs', async () => { |
30 | 22 | const scenario = async () => {
|
31 | 23 | const button = screen.getByText('Action');
|
32 | 24 |
|
33 | 25 | fireEvent.press(button);
|
34 |
| - await screen.findByText('Count: 1'); |
35 |
| - |
36 | 26 | fireEvent.press(button);
|
37 | 27 | await screen.findByText('Count: 2');
|
38 |
| - |
39 |
| - fireEvent.press(button); |
40 |
| - fireEvent.press(button); |
41 |
| - fireEvent.press(button); |
42 |
| - await screen.findByText('Count: 5'); |
43 | 28 | };
|
44 | 29 |
|
45 |
| - await measureRenders(<AsyncComponent />, { scenario }); |
| 30 | + await measureRenders(<AsyncComponent />, { scenario, runs: 50 }); |
46 | 31 | });
|
0 commit comments