Skip to content

Commit b797cf4

Browse files
committed
[v13] chore: remove react 16 & 17 code (#1602)
* chore: remove React 16 & 17 code chore: remove more chore: react version 18.3.1 docs: migration guide * refactor: finish merge
1 parent 398f09a commit b797cf4

File tree

6 files changed

+625
-188
lines changed

6 files changed

+625
-188
lines changed

package.json

+3-4
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
"clean": "del build",
2727
"test": "jest",
2828
"test:ci": "jest --maxWorkers=2 --collectCoverage=true --coverage-provider=v8",
29-
"test:react-17": "scripts/test_react_17",
3029
"typecheck": "tsc",
3130
"flow": "flow",
3231
"copy-flowtypes": "cp typings/index.flow.js build",
@@ -58,9 +57,9 @@
5857
},
5958
"peerDependencies": {
6059
"jest": ">=28.0.0",
61-
"react": ">=16.8.0",
62-
"react-native": ">=0.59",
63-
"react-test-renderer": ">=16.8.0"
60+
"react": ">=18.2.0",
61+
"react-native": ">=0.73",
62+
"react-test-renderer": ">=18.2.0"
6463
},
6564
"peerDependenciesMeta": {
6665
"jest": {

scripts/test_react_17

-12
This file was deleted.

src/act.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// This file and the act() implementation is sourced from react-testing-library
22
// https://github.com/testing-library/react-testing-library/blob/c80809a956b0b9f3289c4a6fa8b5e8cc72d6ef6d/src/act-compat.js
33
import { act as reactTestRendererAct } from 'react-test-renderer';
4-
import { checkReactVersionAtLeast } from './react-versions';
54

65
type ReactAct = typeof reactTestRendererAct;
76

@@ -72,9 +71,7 @@ function withGlobalActEnvironment(actImplementation: ReactAct) {
7271
};
7372
}
7473

75-
const act: ReactAct = checkReactVersionAtLeast(18, 0)
76-
? (withGlobalActEnvironment(reactTestRendererAct) as ReactAct)
77-
: reactTestRendererAct;
74+
const act = withGlobalActEnvironment(reactTestRendererAct) as ReactAct;
7875

7976
export default act;
8077
export { setIsReactActEnvironment as setReactActEnvironment, getIsReactActEnvironment };

src/helpers/wrap-async.ts

+10-26
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
/* istanbul ignore file */
22

3-
import act, { getIsReactActEnvironment, setReactActEnvironment } from '../act';
3+
import { getIsReactActEnvironment, setReactActEnvironment } from '../act';
44
import { flushMicroTasks } from '../flush-micro-tasks';
5-
import { checkReactVersionAtLeast } from '../react-versions';
65

76
/**
87
* Run given async callback with temporarily disabled `act` environment and flushes microtasks queue.
@@ -11,30 +10,15 @@ import { checkReactVersionAtLeast } from '../react-versions';
1110
* @returns Result of the callback
1211
*/
1312
export async function wrapAsync<Result>(callback: () => Promise<Result>): Promise<Result> {
14-
if (checkReactVersionAtLeast(18, 0)) {
15-
const previousActEnvironment = getIsReactActEnvironment();
16-
setReactActEnvironment(false);
13+
const previousActEnvironment = getIsReactActEnvironment();
14+
setReactActEnvironment(false);
1715

18-
try {
19-
const result = await callback();
20-
// Flush the microtask queue before restoring the `act` environment
21-
await flushMicroTasks();
22-
return result;
23-
} finally {
24-
setReactActEnvironment(previousActEnvironment);
25-
}
16+
try {
17+
const result = await callback();
18+
// Flush the microtask queue before restoring the `act` environment
19+
await flushMicroTasks();
20+
return result;
21+
} finally {
22+
setReactActEnvironment(previousActEnvironment);
2623
}
27-
28-
if (!checkReactVersionAtLeast(16, 9)) {
29-
return callback();
30-
}
31-
32-
// Wrapping with act for react version 16.9 to 17.x
33-
let result: Result;
34-
await act(async () => {
35-
result = await callback();
36-
});
37-
38-
// Either we have result or `callback` threw error
39-
return result!;
4024
}

website/docs/MigrationV13.md

+6
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ Migration to React Native Testing Library version 13 from version 12.x.
1313

1414
# Breaking changes
1515

16+
## Supported React and React Native versions
17+
18+
This version supports only React 19 and corresponding React Native versions. If you use React 18 or 19, please use latest of v12 versions.
19+
20+
[Note: at the moment there is no React Native for React 19, and React 19 is still in beta, so we use React 18.3 for the time being].
21+
1622
## Removed deprecated \*ByAccessibilityState queries
1723

1824
This deprecated query has been removed as is typically too general to give meaningful results. Use one of the following options:

0 commit comments

Comments
 (0)