diff --git a/packages/react-client/src/__tests__/ReactFlight-test.js b/packages/react-client/src/__tests__/ReactFlight-test.js
index 681b88f83db02..dcb3eee0b10c3 100644
--- a/packages/react-client/src/__tests__/ReactFlight-test.js
+++ b/packages/react-client/src/__tests__/ReactFlight-test.js
@@ -2103,11 +2103,23 @@ describe('ReactFlight', () => {
function foo() {
return 'hello';
}
+ Object.defineProperty(foo, 'name', {
+ get() {
+ process.stderr.write(new Error('sauce(foo)').stack + '\n');
+ return 'sauce(foo)';
+ },
+ });
function ServerComponent() {
console.log('hi', {prop: 123, fn: foo});
throw new Error('err');
}
+ // Assign to `mockConsoleLog` so we can still inspect it when `console.log`
+ // is overridden by the test modules. The original function will be restored
+ // after this test finishes by `jest.restoreAllMocks()`.
+ const mockConsoleLog = spyOnDevAndProd(console, 'log')
+ .mockImplementation(() => {});
+
let transport;
expect(() => {
// Reset the modules so that we get a new overridden console on top of the
@@ -2120,22 +2132,18 @@ describe('ReactFlight', () => {
transport = ReactNoopFlightServer.render({root: });
}).toErrorDev('err');
- const log = console.log;
- try {
- console.log = jest.fn();
- // The error should not actually get logged because we're not awaiting the root
- // so it's not thrown but the server log also shouldn't be replayed.
- await ReactNoopFlightClient.read(transport);
-
- expect(console.log).toHaveBeenCalledTimes(1);
- expect(console.log.mock.calls[0][0]).toBe('hi');
- expect(console.log.mock.calls[0][1].prop).toBe(123);
- const loggedFn = console.log.mock.calls[0][1].fn;
- expect(typeof loggedFn).toBe('function');
- expect(loggedFn).not.toBe(foo);
- expect(loggedFn.toString()).toBe(foo.toString());
- } finally {
- console.log = log;
- }
+ mockConsoleLog.mockClear();
+
+ // The error should not actually get logged because we're not awaiting the root
+ // so it's not thrown but the server log also shouldn't be replayed.
+ await ReactNoopFlightClient.read(transport);
+
+ expect(mockConsoleLog).toHaveBeenCalledTimes(1);
+ expect(mockConsoleLog.mock.calls[0][0]).toBe('hi');
+ expect(mockConsoleLog.mock.calls[0][1].prop).toBe(123);
+ const loggedFn = mockConsoleLog.mock.calls[0][1].fn;
+ expect(typeof loggedFn).toBe('function');
+ expect(loggedFn).not.toBe(foo);
+ expect(loggedFn.toString()).toBe(foo.toString());
});
});
diff --git a/packages/react-dom/src/__tests__/ReactDOMComponent-test.js b/packages/react-dom/src/__tests__/ReactDOMComponent-test.js
index 5f2c3d14c80e0..4f31ee906d7af 100644
--- a/packages/react-dom/src/__tests__/ReactDOMComponent-test.js
+++ b/packages/react-dom/src/__tests__/ReactDOMComponent-test.js
@@ -1611,7 +1611,7 @@ describe('ReactDOMComponent', () => {
});
it('should work error event on