Skip to content

Commit d4c6303

Browse files
refactor: remove deprecated aliases: update and getQueriesForElement (#1856)
1 parent 16e350f commit d4c6303

File tree

11 files changed

+92
-26
lines changed

11 files changed

+92
-26
lines changed

src/__tests__/within.test.tsx

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

4-
import { getQueriesForElement, render, within } from '..';
4+
import { render, within } from '..';
55

66
test('within() exposes basic queries', async () => {
77
const rootQueries = await render(
@@ -79,7 +79,3 @@ test('within() exposes a11y queries', async () => {
7979
await expect(secondQueries.findAllByLabelText('Same Label')).resolves.toHaveLength(1);
8080
await expect(secondQueries.findAllByA11yHint('Same Hint')).resolves.toHaveLength(1);
8181
});
82-
83-
test('getQueriesForElement is alias to within', () => {
84-
expect(getQueriesForElement).toBe(within);
85-
});

src/matchers/__tests__/to-be-on-the-screen.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ test('toBeOnTheScreen() example test', async () => {
1313
const child = screen.getByTestId('child');
1414
expect(child).toBeOnTheScreen();
1515

16-
await screen.update(<View />);
16+
await screen.rerender(<View />);
1717
expect(child).not.toBeOnTheScreen();
1818
});
1919

@@ -47,7 +47,7 @@ test('toBeOnTheScreen() on detached element', async () => {
4747

4848
const element = screen.getByTestId('text');
4949
// Next line will unmount the element, yet `element` variable will still hold reference to it.
50-
await screen.update(<ShowChildren show={false} />);
50+
await screen.rerender(<ShowChildren show={false} />);
5151

5252
expect(element).toBeTruthy();
5353
expect(element).not.toBeOnTheScreen();

src/matchers/__tests__/to-be-visible.test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ test('toBeVisible() on inaccessible view', async () => {
169169
const test = screen.getByTestId('test', { includeHiddenElements: true });
170170
expect(test).not.toBeVisible();
171171

172-
await screen.update(<View testID="test" />);
172+
await screen.rerender(<View testID="test" />);
173173
expect(test).toBeVisible();
174174
});
175175

@@ -190,7 +190,7 @@ test('toBeVisible() on inaccessible view (iOS)', async () => {
190190
const test = screen.getByTestId('test', { includeHiddenElements: true });
191191
expect(test).not.toBeVisible();
192192

193-
await screen.update(<View testID="test" accessibilityElementsHidden={false} />);
193+
await screen.rerender(<View testID="test" accessibilityElementsHidden={false} />);
194194
expect(test).toBeVisible();
195195
});
196196

@@ -211,7 +211,7 @@ test('toBeVisible() on inaccessible view (Android)', async () => {
211211
const test = screen.getByTestId('test', { includeHiddenElements: true });
212212
expect(test).not.toBeVisible();
213213

214-
await screen.update(<View testID="test" importantForAccessibility="auto" />);
214+
await screen.rerender(<View testID="test" importantForAccessibility="auto" />);
215215
expect(test).toBeVisible();
216216
});
217217

src/pure.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export { fireEvent } from './fire-event';
44
export { render } from './render';
55
export { waitFor } from './wait-for';
66
export { waitForElementToBeRemoved } from './wait-for-element-to-be-removed';
7-
export { within, getQueriesForElement } from './within';
7+
export { within } from './within';
88

99
export { configure, resetToDefaults } from './config';
1010
export { isHiddenFromAccessibility, isInaccessible } from './helpers/accessibility';

src/render.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ export async function render<T>(element: React.ReactElement<T>, options: RenderO
8181
const result = {
8282
...getQueriesForElement(renderer.container),
8383
rerender,
84-
update: rerender, // alias for `rerender`
8584
unmount,
8685
toJSON,
8786
debug: makeDebug(renderer),

src/screen.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ const defaultScreen: Screen = {
2222
},
2323
debug: notImplemented,
2424
rerender: notImplemented,
25-
update: notImplemented,
2625
unmount: notImplemented,
2726
toJSON: notImplemented,
2827
getByLabelText: notImplemented,

website/docs/14.x/docs/advanced/understanding-act.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,10 @@ So far we learned that `act` function allows tests to wait for all pending React
8686
Therefore, we should use `act` whenever there is some action that causes element tree to render, particularly:
8787

8888
- initial render call - `ReactTestRenderer.create` call
89-
- re-rendering of component -`renderer.update` call
89+
- re-rendering of component -`renderer.rerender` call
9090
- triggering any event handlers that cause component tree render
9191

92-
Thankfully, for these basic cases RNTL has got you covered as our `render`, `update` and `fireEvent` methods already wrap their calls in `act` so that you do not have to do it explicitly.
92+
Thankfully, for these basic cases RNTL has got you covered as our `render`, `rerender` and `fireEvent` methods already wrap their calls in `act` so that you do not have to do it explicitly.
9393

9494
Note that `act` calls can be safely nested and internally form a stack of calls. However, overlapping `act` calls, which can be achieved using async version of `act`, [are not supported](https://github.com/facebook/react/blob/main/packages/react/src/ReactAct.js#L161).
9595

website/docs/14.x/docs/api/misc/other.mdx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
# Other helpers
22

3-
## `within`, `getQueriesForElement` {#within}
3+
## `within` {#within}
44

55
```jsx
66
function within(element: HostElement): Queries {}
7-
8-
function getQueriesForElement(element: HostElement): Queries {}
97
```
108

11-
`within` (also available as `getQueriesForElement` alias) performs [queries](docs/api/queries) scoped to given element.
9+
`within` performs [queries](docs/api/queries) scoped to given element.
1210

1311
:::note
14-
Please note that additional `render` specific operations like `update`, `unmount`, `debug`, `toJSON` are _not_ included.
12+
Please note that additional `render` specific operations like `rerender`, `unmount`, `debug`, `toJSON` are _not_ included.
1513
:::
1614

1715
```jsx
@@ -33,7 +31,7 @@ Use cases for scoped queries include:
3331
function act<T>(callback: () => T | Promise<T>): Promise<T>;
3432
```
3533

36-
Useful function to help testing components that use hooks API. By default any `render`, `update`, `fireEvent`, and `waitFor` calls are wrapped by this function, so there is no need to wrap it manually.
34+
Useful function to help testing components that use hooks API. By default any `render`, `rerender`, `fireEvent`, and `waitFor` calls are wrapped by this function, so there is no need to wrap it manually.
3735

3836
**In v14, `act` is now async by default and always returns a Promise**, making it compatible with React 19, React Suspense, and `React.use()`. This ensures all pending React updates are executed before the Promise resolves.
3937

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,6 @@ See [this article](https://kentcdodds.com/blog/common-mistakes-with-react-testin
6363

6464
:::warning Async lifecycle methods
6565

66-
When using `render`, the lifecycle methods `rerender`, `update`, and `unmount` are async and must be awaited.
66+
When using `render`, the lifecycle methods `rerender` and `unmount` are async and must be awaited.
6767

6868
:::

website/docs/14.x/docs/api/screen.mdx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ test('example', async () => {
3535

3636
### `rerender`
3737

38-
_Also available under `update` alias_
39-
4038
```ts
4139
function rerender(element: React.Element<unknown>): Promise<void>;
4240
```

0 commit comments

Comments
 (0)