mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
[tests] assertLog before act in ReactErrorBoundaries (#28761)
Fixes tests blocking https://github.com/facebook/react/pull/28737
This commit is contained in:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user