Skip to content

Commit 19a325d

Browse files
[v14] refactor: render async by default (#1846)
1 parent f534aa7 commit 19a325d

File tree

107 files changed

+1924
-1688
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

107 files changed

+1924
-1688
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"typecheck": "tsc",
3131
"lint": "eslint src --cache",
3232
"validate": "yarn prettier && yarn lint && yarn typecheck && yarn test",
33+
"validate:write": "yarn prettier:write && yarn lint --fix && yarn typecheck && yarn test -u",
3334
"build:js": "babel src --out-dir build --extensions \".js,.ts,.jsx,.tsx\" --source-maps --ignore \"**/__tests__/**\"",
3435
"build:ts": "tsc --build tsconfig.release.json",
3536
"build": "yarn clean && yarn build:js && yarn build:ts",

src/__tests__/__snapshots__/render.test.tsx.snap renamed to src/__tests__/__snapshots__/unsafe-render-sync.test.tsx.snap

File renamed without changes.

src/__tests__/act.test.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,23 @@ const Counter = () => {
1616
return <Text onPress={() => setCount(count + 1)}>{text}</Text>;
1717
};
1818

19-
test('render should trigger useEffect', () => {
19+
test('render should trigger useEffect', async () => {
2020
const effectCallback = jest.fn();
21-
render(<UseEffect callback={effectCallback} />);
21+
await render(<UseEffect callback={effectCallback} />);
2222

2323
expect(effectCallback).toHaveBeenCalledTimes(1);
2424
});
2525

26-
test('rerender should trigger useEffect', () => {
26+
test('rerender should trigger useEffect', async () => {
2727
const effectCallback = jest.fn();
28-
render(<UseEffect callback={effectCallback} />);
29-
screen.rerender(<UseEffect callback={effectCallback} />);
28+
await render(<UseEffect callback={effectCallback} />);
29+
await screen.rerender(<UseEffect callback={effectCallback} />);
3030

3131
expect(effectCallback).toHaveBeenCalledTimes(2);
3232
});
3333

3434
test('fireEvent should trigger useState', async () => {
35-
render(<Counter />);
35+
await render(<Counter />);
3636
const counter = screen.getByText(/Total count/i);
3737

3838
expect(counter.props.children).toEqual('Total count: 0');

src/__tests__/auto-cleanup-skip.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ class Test extends React.Component<{ onUnmount?(): void }> {
2929

3030
// This just verifies that by importing RNTL in pure mode in an environment which supports
3131
// afterEach (like jest) we won't get automatic cleanup between tests.
32-
test('component is mounted, but not umounted before test ends', () => {
32+
test('component is mounted, but not umounted before test ends', async () => {
3333
const fn = jest.fn();
34-
render(<Test onUnmount={fn} />);
34+
await render(<Test onUnmount={fn} />);
3535
expect(fn).not.toHaveBeenCalled();
3636
});
3737

src/__tests__/auto-cleanup.test.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ afterEach(() => {
2727

2828
// This just verifies that by importing RNTL in an environment which supports afterEach (like jest)
2929
// we'll get automatic cleanup between tests.
30-
test('component is mounted, but not umounted before test ends', () => {
30+
test('component is mounted, but not umounted before test ends', async () => {
3131
const fn = jest.fn();
32-
render(<Test onUnmount={fn} />);
32+
await render(<Test onUnmount={fn} />);
3333
expect(isMounted).toEqual(true);
3434
expect(fn).not.toHaveBeenCalled();
3535
});
@@ -38,14 +38,14 @@ test('component is automatically umounted after first test ends', () => {
3838
expect(isMounted).toEqual(false);
3939
});
4040

41-
test('does not time out with legacy fake timers', () => {
41+
test('does not time out with legacy fake timers', async () => {
4242
jest.useFakeTimers({ legacyFakeTimers: true });
43-
render(<Test />);
43+
await render(<Test />);
4444
expect(isMounted).toEqual(true);
4545
});
4646

47-
test('does not time out with fake timers', () => {
47+
test('does not time out with fake timers', async () => {
4848
jest.useFakeTimers();
49-
render(<Test />);
49+
await render(<Test />);
5050
expect(isMounted).toEqual(true);
5151
});

src/__tests__/cleanup.test.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as React from 'react';
22
import { View } from 'react-native';
33

4-
import { cleanupAsync, render, renderAsync } from '../pure';
4+
import { cleanup, render, unsafe_renderSync } from '../pure';
55

66
class Test extends React.Component<{ onUnmount: () => void }> {
77
componentWillUnmount() {
@@ -17,21 +17,21 @@ class Test extends React.Component<{ onUnmount: () => void }> {
1717
test('cleanup after render', async () => {
1818
const fn = jest.fn();
1919

20-
render(<Test onUnmount={fn} />);
21-
render(<Test onUnmount={fn} />);
20+
await render(<Test onUnmount={fn} />);
21+
await render(<Test onUnmount={fn} />);
2222
expect(fn).not.toHaveBeenCalled();
2323

24-
await cleanupAsync();
24+
await cleanup();
2525
expect(fn).toHaveBeenCalledTimes(2);
2626
});
2727

28-
test('cleanup after renderAsync', async () => {
28+
test('cleanup after unsafe_renderSync', async () => {
2929
const fn = jest.fn();
3030

31-
await renderAsync(<Test onUnmount={fn} />);
32-
await renderAsync(<Test onUnmount={fn} />);
31+
unsafe_renderSync(<Test onUnmount={fn} />);
32+
unsafe_renderSync(<Test onUnmount={fn} />);
3333
expect(fn).not.toHaveBeenCalled();
3434

35-
await cleanupAsync();
35+
await cleanup();
3636
expect(fn).toHaveBeenCalledTimes(2);
3737
});

src/__tests__/event-handler.test.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ import { Text, View } from 'react-native';
44
import { render, screen } from '..';
55
import { getEventHandlerFromProps } from '../event-handler';
66

7-
test('getEventHandler strict mode', () => {
7+
test('getEventHandler strict mode', async () => {
88
const onPress = jest.fn();
99
const testOnlyOnPress = jest.fn();
1010

11-
render(
11+
await render(
1212
<View>
1313
<Text testID="regular" onPress={onPress} />
1414
{/* @ts-expect-error Intentionally passing such props */}
@@ -31,11 +31,11 @@ test('getEventHandler strict mode', () => {
3131
expect(getEventHandlerFromProps(both.props, 'onPress')).toBe(undefined);
3232
});
3333

34-
test('getEventHandler loose mode', () => {
34+
test('getEventHandler loose mode', async () => {
3535
const onPress = jest.fn();
3636
const testOnlyOnPress = jest.fn();
3737

38-
render(
38+
await render(
3939
<View>
4040
<Text testID="regular" onPress={onPress} />
4141
{/* @ts-expect-error Intentionally passing such props */}

src/__tests__/fire-event-textInput.test.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ test('should fire only non-touch-related events on non-editable TextInput', asyn
2020
const onSubmitEditing = jest.fn();
2121
const onLayout = jest.fn();
2222

23-
render(
23+
await render(
2424
<TextInput
2525
editable={false}
2626
testID="subject"
@@ -49,7 +49,7 @@ test('should fire only non-touch-related events on non-editable TextInput with n
4949
const onSubmitEditing = jest.fn();
5050
const onLayout = jest.fn();
5151

52-
render(
52+
await render(
5353
<TextInput
5454
editable={false}
5555
testID="subject"
@@ -100,7 +100,7 @@ test('should fire only non-touch-related events on non-editable wrapped TextInpu
100100
const onSubmitEditing = jest.fn();
101101
const onLayout = jest.fn();
102102

103-
render(
103+
await render(
104104
<WrappedTextInput
105105
editable={false}
106106
testID="subject"
@@ -132,7 +132,7 @@ test('should fire only non-touch-related events on non-editable double wrapped T
132132
const onSubmitEditing = jest.fn();
133133
const onLayout = jest.fn();
134134

135-
render(
135+
await render(
136136
<DoubleWrappedTextInput
137137
editable={false}
138138
testID="subject"

0 commit comments

Comments
 (0)