Skip to content

Commit d0d571d

Browse files
committed
fix: compatibility with react 19 in snapshots
1 parent fd3d6cf commit d0d571d

File tree

3 files changed

+27
-10
lines changed

3 files changed

+27
-10
lines changed

packages/pretty-format/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@
2323
"dependencies": {
2424
"@jest/schemas": "workspace:*",
2525
"ansi-styles": "^5.2.0",
26-
"react-is": "^18.3.1"
26+
"react-is": "^19.1.0"
2727
},
2828
"devDependencies": {
2929
"@types/react": "^18.3.23",
30-
"@types/react-is": "^18.3.1",
30+
"@types/react-is": "^19.0.0",
3131
"@types/react-test-renderer": "^18.3.1",
3232
"immutable": "^5.1.2",
3333
"jest-util": "workspace:*",

packages/pretty-format/src/plugins/ReactElement.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,16 @@ const getPropKeys = (element: any) => {
7979
.sort();
8080
};
8181

82+
// Compatibility with react <19
83+
const isLegacyReactElement = (val: unknown) => {
84+
return (
85+
val !== null &&
86+
typeof val === 'object' &&
87+
'$$typeof' in val &&
88+
val.$$typeof === Symbol.for('react.element')
89+
);
90+
};
91+
8292
export const serialize: NewPlugin['serialize'] = (
8393
element: any,
8494
config: Config,
@@ -113,7 +123,7 @@ export const serialize: NewPlugin['serialize'] = (
113123
);
114124

115125
export const test: NewPlugin['test'] = (val: unknown) =>
116-
val != null && ReactIs.isElement(val);
126+
(val != null && ReactIs.isElement(val)) || isLegacyReactElement(val);
117127

118128
const plugin: NewPlugin = {serialize, test};
119129

yarn.lock

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6390,12 +6390,12 @@ __metadata:
63906390
languageName: node
63916391
linkType: hard
63926392

6393-
"@types/react-is@npm:^18.3.1":
6394-
version: 18.3.1
6395-
resolution: "@types/react-is@npm:18.3.1"
6393+
"@types/react-is@npm:^19.0.0":
6394+
version: 19.0.0
6395+
resolution: "@types/react-is@npm:19.0.0"
63966396
dependencies:
6397-
"@types/react": "npm:^18"
6398-
checksum: 10/ccb79d6e196a5232cde8ccb255ec97e062801a3dafeff3816130fb5ad6b9a87f7c0806ab35bc00890a229773228ef217d0390839b68c705d3add2f798b5fcf82
6397+
"@types/react": "npm:*"
6398+
checksum: 10/c56e39e88558a71bc0b1deaa84cce9d5c84d6522057b73690d099b0763898203ec29a91563431e83b5086c49ac64a239fe993c50a4f008d6fbfc551587db5895
63996399
languageName: node
64006400
linkType: hard
64016401

@@ -18234,14 +18234,14 @@ __metadata:
1823418234
dependencies:
1823518235
"@jest/schemas": "workspace:*"
1823618236
"@types/react": "npm:^18.3.23"
18237-
"@types/react-is": "npm:^18.3.1"
18237+
"@types/react-is": "npm:^19.0.0"
1823818238
"@types/react-test-renderer": "npm:^18.3.1"
1823918239
ansi-styles: "npm:^5.2.0"
1824018240
immutable: "npm:^5.1.2"
1824118241
jest-util: "workspace:*"
1824218242
react: "npm:18.3.1"
1824318243
react-dom: "npm:18.3.1"
18244-
react-is: "npm:^18.3.1"
18244+
react-is: "npm:^19.1.0"
1824518245
react-test-renderer: "npm:18.3.1"
1824618246
languageName: unknown
1824718247
linkType: soft
@@ -18637,6 +18637,13 @@ __metadata:
1863718637
languageName: node
1863818638
linkType: hard
1863918639

18640+
"react-is@npm:^19.1.0":
18641+
version: 19.1.0
18642+
resolution: "react-is@npm:19.1.0"
18643+
checksum: 10/4aceca94492032a19411138bf68c6ca7dce4abee7ae6c7f23db9291d2dff14d6a643717b176ef9a151e8cdf6a2b71fdbc59fd998328e086a6f752512304a252b
18644+
languageName: node
18645+
linkType: hard
18646+
1864018647
"react-json-view-lite@npm:^1.2.0":
1864118648
version: 1.5.0
1864218649
resolution: "react-json-view-lite@npm:1.5.0"

0 commit comments

Comments
 (0)