Skip to content

Commit 269bd40

Browse files
eps1lonclaude
andauthored
[test] Remove the custom toThrow override for legacy V8 error messages (react#37384)
The custom `toThrow` override in `scripts/jest/matchers/toThrow.js` wrapped the built-in matcher to rewrite the pre-Node-17 V8 error message format ("Cannot read property 'x' of undefined") into the modern one ("Cannot read properties of undefined (reading 'x')"), so the test suite could run on Node 12 to 16. On the Node versions this repo runs on (20 per `.nvmrc`, 24 in CI), V8 only ever produces the modern format, so the override is a passthrough. Mostly removing this because the custom matcher deep-imports `expect/build/toThrowMatchers`, which no longer resolves on Jest 30 because each Jest package is now bundled into a single file, so this removal unblocks the Jest 30 upgrade stacked on top. Co-authored-by: Claude Code (kimi-k3[1m]) <noreply@anthropic.com>
1 parent a112448 commit 269bd40

5 files changed

Lines changed: 9 additions & 61 deletions

File tree

packages/react-dom/src/__tests__/ReactServerRendering-test.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -147,15 +147,15 @@ describe('ReactDOMServer', () => {
147147
it('should throw with silly args', () => {
148148
expect(
149149
ReactDOMServer.renderToString.bind(ReactDOMServer, {x: 123}),
150-
).toThrowError(
150+
).toThrow(
151151
'Objects are not valid as a React child (found: object with keys {x})',
152152
);
153153
});
154154

155155
it('should throw prop mapping error for an <iframe /> with invalid props', () => {
156156
expect(() => {
157157
ReactDOMServer.renderToString(<iframe style="border:none;" />);
158-
}).toThrowError(
158+
}).toThrow(
159159
'The `style` prop expects a mapping from style properties to values, not ' +
160160
"a string. For example, style={{marginRight: spacing + 'em'}} when using JSX.",
161161
);
@@ -290,7 +290,7 @@ describe('ReactDOMServer', () => {
290290
it('should throw with silly args', () => {
291291
expect(
292292
ReactDOMServer.renderToStaticMarkup.bind(ReactDOMServer, {x: 123}),
293-
).toThrowError(
293+
).toThrow(
294294
'Objects are not valid as a React child (found: object with keys {x})',
295295
);
296296
});
@@ -715,7 +715,7 @@ describe('ReactDOMServer', () => {
715715
<span key={2} />
716716
</Wrapper>,
717717
);
718-
}).toThrowError(/Cannot assign to read only property.*/);
718+
}).toThrow(/Cannot assign to read only property.*/);
719719
} else {
720720
expect(
721721
ReactDOMServer.renderToStaticMarkup(
@@ -966,7 +966,7 @@ describe('ReactDOMServer', () => {
966966

967967
expect(() => {
968968
ReactDOMServer.renderToString(<Foo />);
969-
}).toThrow("Cannot read property 'world' of undefined");
969+
}).toThrow("Cannot read properties of undefined (reading 'world')");
970970
});
971971

972972
it('should warn when class contextType is undefined', () => {
@@ -981,7 +981,7 @@ describe('ReactDOMServer', () => {
981981

982982
expect(() => {
983983
ReactDOMServer.renderToString(<Foo />);
984-
}).toThrow("Cannot read property 'world' of undefined");
984+
}).toThrow("Cannot read properties of undefined (reading 'world')");
985985
assertConsoleErrorDev([
986986
'Foo defines an invalid contextType. ' +
987987
'contextType should point to the Context object returned by React.createContext(). ' +
@@ -1007,7 +1007,7 @@ describe('ReactDOMServer', () => {
10071007

10081008
expect(() => {
10091009
ReactDOMServer.renderToString(<Foo />);
1010-
}).toThrow("Cannot read property 'hello' of undefined");
1010+
}).toThrow("Cannot read properties of undefined (reading 'hello')");
10111011
assertConsoleErrorDev([
10121012
'Foo defines an invalid contextType. ' +
10131013
'contextType should point to the Context object returned by React.createContext(). ' +
@@ -1026,7 +1026,7 @@ describe('ReactDOMServer', () => {
10261026

10271027
expect(() => {
10281028
ReactDOMServer.renderToString(<Foo />);
1029-
}).toThrow("Cannot read property 'world' of undefined");
1029+
}).toThrow("Cannot read properties of undefined (reading 'world')");
10301030
assertConsoleErrorDev([
10311031
'Foo defines an invalid contextType. ' +
10321032
'contextType should point to the Context object returned by React.createContext(). ' +

packages/react-reconciler/src/__tests__/ReactHooksWithNoopRenderer-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ describe('ReactHooksWithNoopRenderer', () => {
234234

235235
it('throws when called outside the render phase', async () => {
236236
expect(() => useState(0)).toThrow(
237-
"Cannot read property 'useState' of null",
237+
"Cannot read properties of null (reading 'useState')",
238238
);
239239
assertConsoleErrorDev([
240240
'Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for' +

scripts/jest/matchers/toThrow.js

Lines changed: 0 additions & 50 deletions
This file was deleted.

scripts/jest/setupTests.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ if (process.env.REACT_CLASS_EQUIVALENCE_TEST) {
4747

4848
expect.extend({
4949
...require('./matchers/reactTestMatchers'),
50-
...require('./matchers/toThrow'),
5150
});
5251

5352
// We have a Babel transform that inserts guards against infinite loops.

scripts/jest/spec-equivalence-reporter/setupTests.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,4 @@ afterEach(assertConsoleLogsCleared);
6060

6161
expect.extend({
6262
...require('../matchers/reactTestMatchers'),
63-
...require('../matchers/toThrow'),
6463
});

0 commit comments

Comments
 (0)