Skip to content

Commit 1aef26b

Browse files
committed
fix issues
1 parent 7842092 commit 1aef26b

File tree

4 files changed

+13
-22
lines changed

4 files changed

+13
-22
lines changed

src/__tests__/render-async.test.tsx

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,15 @@ test('rerender function throws error when used with renderAsync', async () => {
6868
const result = await renderAsync(<Banana />);
6969

7070
expect(() => result.rerender(<Banana />)).toThrowErrorMatchingInlineSnapshot(
71-
`"\`rerender(...)\` is not supported when using \`renderAsync\` use \`await rerenderAsync(...)\` instead"`
71+
`"\`rerender(...)\` is not supported when using \`renderAsync\` use \`await rerenderAsync(...)\` instead"`,
7272
);
7373
});
7474

7575
test('rerenderAsync function updates component asynchronously', async () => {
7676
const fn = jest.fn();
7777
const result = await renderAsync(<Banana onUpdate={fn} />);
7878
expect(fn).toHaveBeenCalledTimes(0);
79-
79+
8080
await result.rerenderAsync(<Banana onUpdate={fn} />);
8181
expect(fn).toHaveBeenCalledTimes(1);
8282
});
@@ -85,24 +85,15 @@ test('rerender function throws error when used with renderAsync', async () => {
8585
const result = await renderAsync(<Banana />);
8686

8787
expect(() => result.rerender(<Banana />)).toThrowErrorMatchingInlineSnapshot(
88-
`"\`rerender(...)\` is not supported when using \`renderAsync\` use \`await rerenderAsync(...)\` instead"`
88+
`"\`rerender(...)\` is not supported when using \`renderAsync\` use \`await rerenderAsync(...)\` instead"`,
8989
);
9090
});
9191

92-
test('rerenderAsync function updates component asynchronously', async () => {
93-
const fn = jest.fn();
94-
const result = await renderAsync(<Banana onUpdate={fn} />);
95-
expect(fn).toHaveBeenCalledTimes(0);
96-
97-
await result.rerenderAsync(<Banana onUpdate={fn} />);
98-
expect(fn).toHaveBeenCalledTimes(1);
99-
});
100-
10192
test('unmount function throws error when used with renderAsync', async () => {
10293
const result = await renderAsync(<Banana />);
10394

10495
expect(() => result.unmount()).toThrowErrorMatchingInlineSnapshot(
105-
`"\`unmount()\` is not supported when using \`renderAsync\` use \`await unmountAsync()\` instead"`
96+
`"\`unmount()\` is not supported when using \`renderAsync\` use \`await unmountAsync()\` instead"`,
10697
);
10798
});
10899

src/__tests__/render.test.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,16 @@ test('UNSAFE_getAllByProp, UNSAFE_queryAllByProps', () => {
110110
expect(screen.UNSAFE_queryAllByProps({ type: 'inexistent' })).toHaveLength(0);
111111
});
112112

113-
test('update', () => {
113+
test('rerender', () => {
114114
const fn = jest.fn();
115115
render(<Banana onUpdate={fn} />);
116+
expect(fn).toHaveBeenCalledTimes(0);
116117

117118
fireEvent.press(screen.getByText('Change freshness!'));
119+
expect(fn).toHaveBeenCalledTimes(1);
118120

119-
screen.update(<Banana onUpdate={fn} />);
120121
screen.rerender(<Banana onUpdate={fn} />);
121-
122-
expect(fn).toHaveBeenCalledTimes(3);
122+
expect(fn).toHaveBeenCalledTimes(2);
123123
});
124124

125125
test('unmount', () => {

src/render-async.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ function buildRenderResult(
6262
) {
6363
const instance = renderer.root;
6464

65-
const rerender = function (component: React.ReactElement) {
65+
const rerender = function (_component: React.ReactElement) {
6666
throw new Error(
6767
'`rerender(...)` is not supported when using `renderAsync` use `await rerenderAsync(...)` instead',
6868
);

website/docs/13.x/docs/api/render.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,10 @@ test('async component test', async () => {
9797

9898
### Result
9999

100-
The `renderAsync` function returns a promise that resolves to the same queries and utilities as the [`screen`](docs/api/screen) object. We recommend using the `screen` object for queries and the async lifecycle methods from the render result when needed.
100+
The `renderAsync` function returns a promise that resolves to the same queries and utilities as the [`screen`](docs/api/screen) object. We recommend using the `screen` object for queries and the lifecycle methods from the render result when needed.
101101

102-
:::note Async lifecycle methods
102+
:::warning Async lifecycle methods
103103

104-
When using `renderAsync`, you have to use correspodning lifecycle methods: `updateAsync`/`rerenderAsync` and `unmountAsync` instead of their sync versions.
104+
When using `renderAsync`, you have to use correspodning lifecycle methods: `rerenderAsync` and `unmountAsync` instead of their sync versions.
105105

106-
::
106+
:::

0 commit comments

Comments
 (0)