Repository: facebook/react
Pull request: [tests] assertLog before act in ReactErrorBoundaries

Fixes tests blocking https://github.com/facebook/react/pull/28737

Changed files:
filename: packages/react-dom/src/__tests__/ReactErrorBoundaries-test.internal.js
patch: @@ -584,6 +584,7 @@ describe('ReactErrorBoundaries', () => {
       });
     }).rejects.toThrow('Hello');
 
+    Scheduler.unstable_clearLog();
     container = document.createElement('div');
     root = ReactDOMClient.createRoot(container);
     await expect(async () => {
@@ -592,6 +593,7 @@ describe('ReactErrorBoundaries', () => {
       });
     }).rejects.toThrow('Hello');
 
+    Scheduler.unstable_clearLog();
     container = document.createElement('div');
     root = ReactDOMClient.createRoot(container);
     await expect(async () => {
@@ -607,28 +609,32 @@ describe('ReactErrorBoundaries', () => {
     await act(async () => {
       root.render(<BrokenComponentWillUpdate />);
     });
+    Scheduler.unstable_clearLog();
     await expect(async () => {
       await act(async () => {
         root.render(<BrokenComponentWillUpdate />);
       });
     }).rejects.toThrow('Hello');
 
+    Scheduler.unstable_clearLog();
     container = document.createElement('div');
     root = ReactDOMClient.createRoot(container);
     await act(async () => {
       root.render(<BrokenComponentWillReceiveProps />);
     });
+    Scheduler.unstable_clearLog();
     await expect(async () => {
       await act(async () => {
         root.render(<BrokenComponentWillReceiveProps />);
       });
     }).rejects.toThrow('Hello');
-
+    Scheduler.unstable_clearLog();
     container = document.createElement('div');
     root = ReactDOMClient.createRoot(container);
     await act(async () => {
       root.render(<BrokenComponentDidUpdate />);
     });
+    Scheduler.unstable_clearLog();
     await expect(async () => {
       await act(async () => {
         root.render(<BrokenComponentDidUpdate />);
@@ -642,6 +648,7 @@ describe('ReactErrorBoundaries', () => {
     await act(async () => {
       root.render(<BrokenComponentWillUnmount />);
     });
+    Scheduler.unstable_clearLog();
     await expect(async () => {
       await act(() => root.unmount());
     }).rejects.toThrow('Hello');
@@ -663,6 +670,15 @@ describe('ReactErrorBoundaries', () => {
         root2.render(<BrokenRender />);
       });
     }).rejects.toThrow('Hello');
+
+    assertLog([
+      'BrokenRender constructor',
+      'BrokenRender componentWillMount',
+      'BrokenRender render [!]',
+      'BrokenRender constructor',
+      'BrokenRender componentWillMount',
+      'BrokenRender render [!]',
+    ]);
     await act(async () => {
       root3.render(
         <ErrorBoundary>
@@ -674,12 +690,15 @@ describe('ReactErrorBoundaries', () => {
     expect(container2.firstChild).toBe(null);
     expect(container3.firstChild.textContent).toBe('Caught an error: Hello.');
 
+    Scheduler.unstable_clearLog();
     await act(async () => {
       root1.render(<span>After 1</span>);
     });
+    Scheduler.unstable_clearLog();
     await act(async () => {
       root2.render(<span>After 2</span>);
     });
+    Scheduler.unstable_clearLog();
     await act(async () => {
       root3.render(<ErrorBoundary forceRetry={true}>After 3</ErrorBoundary>);
     });
@@ -1828,6 +1847,7 @@ describe('ReactErrorBoundaries', () => {
       );
     });
 
+    Scheduler.unstable_clearLog();
     await act(async () => {
       root.render(
         <ErrorBoundary>
@@ -1879,6 +1899,7 @@ describe('ReactErrorBoundaries', () => {
       );
     });
     expect(container.textContent).toBe('Caught an error: Hello.');
+    Scheduler.unstable_clearLog();
 
     await act(async () => {
       root.render(
@@ -1888,6 +1909,7 @@ describe('ReactErrorBoundaries', () => {
       );
     });
     expect(container.textContent).toBe('Caught an error: Hello.');
+    Scheduler.unstable_clearLog();
 
     await act(async () => {
       root.render(<div>Other screen</div>);
@@ -1909,7 +1931,7 @@ describe('ReactErrorBoundaries', () => {
         </ErrorBoundary>,
       );
     });
-
+    Scheduler.unstable_clearLog();
     await act(async () => {
       root.render(<ErrorBoundary />);
     });
@@ -1926,6 +1948,12 @@ describe('ReactErrorBoundaries', () => {
     await act(async () => {
       root.render(<ErrorBoundary />);
     });
+    assertLog([
+      'ErrorBoundary constructor',
+      'ErrorBoundary componentWillMount',
+      'ErrorBoundary render success',
+      'ErrorBoundary componentDidMount',
+    ]);
     await act(async () => {
       root.render(
         <ErrorBoundary>
@@ -1983,6 +2011,7 @@ describe('ReactErrorBoundaries', () => {
     expect(container.textContent).not.toContain('Caught an error');
 
     fail = true;
+    Scheduler.unstable_clearLog();
     await act(async () => {
       root.render(
         <ErrorBoundary>