[tests] assertLog before act in ReactErrorBoundaries (#28761)
Fixes tests blocking https://github.com/facebook/react/pull/28737
Ricky committed
Apr 10, 2024 at 10:34 UTC
b02199d322c3876f213dc9bba815acaa839609fd
1 file changed
+31
-2
packages/react-dom/src/__tests__/ReactErrorBoundaries-test.internal.js
+31
-2
@@ -584,6 +584,7 @@ describe('ReactErrorBoundaries', () => {
584
});
585
}).rejects.toThrow('Hello');
586
587
+ Scheduler.unstable_clearLog();
588
container = document.createElement('div');
589
root = ReactDOMClient.createRoot(container);
590
await expect(async () => {
@@ -592,6 +593,7 @@ describe('ReactErrorBoundaries', () => {
593
});
594
}).rejects.toThrow('Hello');
595
596
+ Scheduler.unstable_clearLog();
597
container = document.createElement('div');
598
root = ReactDOMClient.createRoot(container);
599
await expect(async () => {
@@ -607,28 +609,32 @@ describe('ReactErrorBoundaries', () => {
609
await act(async () => {
610
root.render(<BrokenComponentWillUpdate />);
611
});
612
+ Scheduler.unstable_clearLog();
613
await expect(async () => {
614
await act(async () => {
615
root.render(<BrokenComponentWillUpdate />);
616
});
617
}).rejects.toThrow('Hello');
618
619
+ Scheduler.unstable_clearLog();
620
container = document.createElement('div');
621
root = ReactDOMClient.createRoot(container);
622
await act(async () => {
623
root.render(<BrokenComponentWillReceiveProps />);
624
});
625
+ Scheduler.unstable_clearLog();
626
await expect(async () => {
627
await act(async () => {
628
root.render(<BrokenComponentWillReceiveProps />);
629
});
630
}).rejects.toThrow('Hello');
626
-
631
+ Scheduler.unstable_clearLog();
632
container = document.createElement('div');
633
root = ReactDOMClient.createRoot(container);
634
await act(async () => {
635
root.render(<BrokenComponentDidUpdate />);
636
});
637
+ Scheduler.unstable_clearLog();
638
await expect(async () => {
639
await act(async () => {
640
root.render(<BrokenComponentDidUpdate />);
@@ -642,6 +648,7 @@ describe('ReactErrorBoundaries', () => {
648
await act(async () => {
649
root.render(<BrokenComponentWillUnmount />);
650
});
651
+ Scheduler.unstable_clearLog();
652
await expect(async () => {
653
await act(() => root.unmount());
654
}).rejects.toThrow('Hello');
@@ -663,6 +670,15 @@ describe('ReactErrorBoundaries', () => {
670
root2.render(<BrokenRender />);
671
});
672
}).rejects.toThrow('Hello');
673
+
674
+ assertLog([
675
+ 'BrokenRender constructor',
676
+ 'BrokenRender componentWillMount',
677
+ 'BrokenRender render [!]',
678
+ 'BrokenRender constructor',
679
+ 'BrokenRender componentWillMount',
680
+ 'BrokenRender render [!]',
681
+ ]);
682
await act(async () => {
683
root3.render(
684
<ErrorBoundary>
@@ -674,12 +690,15 @@ describe('ReactErrorBoundaries', () => {
690
expect(container2.firstChild).toBe(null);
691
expect(container3.firstChild.textContent).toBe('Caught an error: Hello.');
692
693
+ Scheduler.unstable_clearLog();
694
await act(async () => {
695
root1.render(<span>After 1</span>);
696
});
697
+ Scheduler.unstable_clearLog();
698
await act(async () => {
699
root2.render(<span>After 2</span>);
700
});
701
+ Scheduler.unstable_clearLog();
702
await act(async () => {
703
root3.render(<ErrorBoundary forceRetry={true}>After 3</ErrorBoundary>);
704
});
@@ -1828,6 +1847,7 @@ describe('ReactErrorBoundaries', () => {
1847
);
1848
});
1849
1850
+ Scheduler.unstable_clearLog();
1851
await act(async () => {
1852
root.render(
1853
<ErrorBoundary>
@@ -1879,6 +1899,7 @@ describe('ReactErrorBoundaries', () => {
1899
);
1900
});
1901
expect(container.textContent).toBe('Caught an error: Hello.');
1902
+ Scheduler.unstable_clearLog();
1903
1904
await act(async () => {
1905
root.render(
@@ -1888,6 +1909,7 @@ describe('ReactErrorBoundaries', () => {
1909
);
1910
});
1911
expect(container.textContent).toBe('Caught an error: Hello.');
1912
+ Scheduler.unstable_clearLog();
1913
1914
await act(async () => {
1915
root.render(<div>Other screen</div>);
@@ -1909,7 +1931,7 @@ describe('ReactErrorBoundaries', () => {
1931
</ErrorBoundary>,
1932
);
1933
});
1912
-
1934
+ Scheduler.unstable_clearLog();
1935
await act(async () => {
1936
root.render(<ErrorBoundary />);
1937
});
@@ -1926,6 +1948,12 @@ describe('ReactErrorBoundaries', () => {
1948
await act(async () => {
1949
root.render(<ErrorBoundary />);
1950
});
1951
+ assertLog([
1952
+ 'ErrorBoundary constructor',
1953
+ 'ErrorBoundary componentWillMount',
1954
+ 'ErrorBoundary render success',
1955
+ 'ErrorBoundary componentDidMount',
1956
+ ]);
1957
await act(async () => {
1958
root.render(
1959
<ErrorBoundary>
@@ -1983,6 +2011,7 @@ describe('ReactErrorBoundaries', () => {
2011
expect(container.textContent).not.toContain('Caught an error');
2012
2013
fail = true;
2014
+ Scheduler.unstable_clearLog();
2015
await act(async () => {
2016
root.render(
2017
<ErrorBoundary>