Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support passthrough updates for error boundaries #7949

Merged
merged 23 commits into from
Oct 15, 2016
Merged
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
7ebc488
Initial pass at the easy case of updates (updates that start at the r…
jimfb Feb 11, 2016
9017999
Don't expect an extra componentWillUnmount call
gaearon Oct 12, 2016
965d12f
Remove duplicate expectations from the test
gaearon Oct 12, 2016
8236279
Fix style issues
gaearon Oct 12, 2016
d09d33f
Make naming consistent throughout the tests
gaearon Oct 12, 2016
aedd80d
receiveComponent() does not accept safely argument
gaearon Oct 12, 2016
5f869d2
Assert that lifecycle and refs fire for error message
gaearon Oct 12, 2016
3890a3a
Add more tests for mounting
gaearon Oct 13, 2016
045dcb5
Do not call componentWillMount twice on error boundary
gaearon Oct 13, 2016
b69d428
Document more of existing behavior in tests
gaearon Oct 13, 2016
e374fc7
Do not call componentWillUnmount() when aborting mounting
gaearon Oct 13, 2016
1fa0b36
Consistently display error messages in tests
gaearon Oct 14, 2016
8066a50
Add more logging to tests and remove redundant one
gaearon Oct 14, 2016
b0e6a08
Refactor tests
gaearon Oct 14, 2016
842bd75
Split complicated tests into smaller ones
gaearon Oct 14, 2016
0783dee
Assert clean unmounting
gaearon Oct 14, 2016
b36526e
Add assertions about update hooks
gaearon Oct 14, 2016
db4c306
Add more tests to document existing behavior and remove irrelevant de…
gaearon Oct 14, 2016
99dad51
Verify we can recover from error state
gaearon Oct 14, 2016
de5bdf1
Fix lint
gaearon Oct 14, 2016
c64dbfd
Error in boundary’s componentWillMount should propagate up
gaearon Oct 14, 2016
7026adc
Move calling componentWillMount() into mountComponent()
gaearon Oct 14, 2016
9f66fa4
Remove extra whitespace
gaearon Oct 14, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Assert clean unmounting
  • Loading branch information
gaearon committed Oct 14, 2016
commit 0783dee8810381dfa62f99cfabf7f6f93d5f5c40
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,12 @@ describe('ReactErrorBoundaries', () => {
'ErrorBoundary render error',
'ErrorBoundary componentDidMount',
]);

log.length = 0;
ReactDOM.unmountComponentAtNode(container);
expect(log).toEqual([
'ErrorBoundary componentWillUnmount',
]);
});

it('renders an error state if child throws in constructor', () => {
Expand All @@ -316,6 +322,12 @@ describe('ReactErrorBoundaries', () => {
'ErrorBoundary render error',
'ErrorBoundary componentDidMount',
]);

log.length = 0;
ReactDOM.unmountComponentAtNode(container);
expect(log).toEqual([
'ErrorBoundary componentWillUnmount',
]);
});

it('renders an error state if child throws in componentWillMount', () => {
Expand All @@ -338,6 +350,12 @@ describe('ReactErrorBoundaries', () => {
'ErrorBoundary render error',
'ErrorBoundary componentDidMount',
]);

log.length = 0;
ReactDOM.unmountComponentAtNode(container);
expect(log).toEqual([
'ErrorBoundary componentWillUnmount',
]);
});

it('mounts the error message if mounting fails', () => {
Expand Down Expand Up @@ -371,6 +389,13 @@ describe('ReactErrorBoundaries', () => {
'ErrorMessage componentDidMount',
'ErrorBoundary componentDidMount',
]);

log.length = 0;
ReactDOM.unmountComponentAtNode(container);
expect(log).toEqual([
'ErrorBoundary componentWillUnmount',
'ErrorMessage componentWillUnmount',
]);
});

// Known limitation because componentDidMount() does not occur on the stack.
Expand Down Expand Up @@ -399,6 +424,13 @@ describe('ReactErrorBoundaries', () => {
// 'ErrorBoundary render error',
// 'ErrorBoundary componentDidMount',
]);

log.length = 0;
ReactDOM.unmountComponentAtNode(container);
expect(log).toEqual([
'ErrorBoundary componentWillUnmount',
'BrokenComponentDidMount componentWillUnmount',
]);
});

it('propagates errors on retry on mounting', () => {
Expand Down Expand Up @@ -435,6 +467,12 @@ describe('ReactErrorBoundaries', () => {
'ErrorBoundary render error',
'ErrorBoundary componentDidMount',
]);

log.length = 0;
ReactDOM.unmountComponentAtNode(container);
expect(log).toEqual([
'ErrorBoundary componentWillUnmount',
]);
});

it('propagates errors inside boundary itself on mounting', () => {
Expand Down Expand Up @@ -468,6 +506,12 @@ describe('ReactErrorBoundaries', () => {
'ErrorBoundary render error',
'ErrorBoundary componentDidMount',
]);

log.length = 0;
ReactDOM.unmountComponentAtNode(container);
expect(log).toEqual([
'ErrorBoundary componentWillUnmount',
]);
});

it('does not register event handlers for unmounted children', () => {
Expand All @@ -482,6 +526,12 @@ describe('ReactErrorBoundaries', () => {
container
);
expect(EventPluginHub.putListener).not.toBeCalled();

log.length = 0;
ReactDOM.unmountComponentAtNode(container);
expect(log).toEqual([
'ErrorBoundary componentWillUnmount',
]);
});

it('does not call componentWillUnmount when aborting initial mount', () => {
Expand All @@ -495,7 +545,6 @@ describe('ReactErrorBoundaries', () => {
container
);
expect(container.firstChild.textContent).toBe('Caught an error: Hello.');
ReactDOM.unmountComponentAtNode(container);
expect(log).toEqual([
'ErrorBoundary constructor',
'ErrorBoundary componentWillMount',
Expand All @@ -512,8 +561,13 @@ describe('ReactErrorBoundaries', () => {
'ErrorBoundary unstable_handleError',
// Render the error message
'ErrorBoundary render error',
'ErrorBoundary componentDidMount',
'ErrorBoundary componentWillUnmount'
'ErrorBoundary componentDidMount'
]);

log.length = 0;
ReactDOM.unmountComponentAtNode(container);
expect(log).toEqual([
'ErrorBoundary componentWillUnmount',
]);
});

Expand Down Expand Up @@ -574,6 +628,12 @@ describe('ReactErrorBoundaries', () => {
'ErrorBoundary render success',
'ErrorBoundary componentDidMount',
]);

log.length = 0;
ReactDOM.unmountComponentAtNode(container);
expect(log).toEqual([
'ErrorBoundary componentWillUnmount',
]);
});

it('catches if child throws in render during update', () => {
Expand Down Expand Up @@ -622,6 +682,12 @@ describe('ReactErrorBoundaries', () => {
// Normal2 does not get lifefycle because it was never mounted
'ErrorBoundary render error'
]);

log.length = 0;
ReactDOM.unmountComponentAtNode(container);
expect(log).toEqual([
'ErrorBoundary componentWillUnmount',
]);
});

it('keeps refs up-to-date during updates', () => {
Expand Down Expand Up @@ -821,15 +887,18 @@ describe('ReactErrorBoundaries', () => {
container
);
expect(container.textContent).toBe('Caught an error: Hello.');

ReactDOM.render(
<ErrorBoundary>
<BrokenRender />
</ErrorBoundary>,
container
);
expect(container.textContent).toBe('Caught an error: Hello.');

ReactDOM.render(<div>Other screen</div>, container);
expect(container.textContent).toBe('Other screen');

ReactDOM.unmountComponentAtNode(container);
});

Expand All @@ -843,9 +912,15 @@ describe('ReactErrorBoundaries', () => {
</ErrorBoundary>,
container
);

ReactDOM.render(<ErrorBoundary />, container);
expect(container.textContent).toBe('Caught an error: Hello.');

log.length = 0;
ReactDOM.unmountComponentAtNode(container);
expect(log).toEqual([
'ErrorBoundary componentWillUnmount',
]);
});

it('doesn\'t get into inconsistent state during additions', () => {
Expand All @@ -860,7 +935,12 @@ describe('ReactErrorBoundaries', () => {
container
);
expect(container.textContent).toBe('Caught an error: Hello.');

log.length = 0;
ReactDOM.unmountComponentAtNode(container);
expect(log).toEqual([
'ErrorBoundary componentWillUnmount',
]);
});

it('doesn\'t get into inconsistent state during reorders', () => {
Expand Down Expand Up @@ -909,6 +989,11 @@ describe('ReactErrorBoundaries', () => {
container
);
expect(container.textContent).toBe('Caught an error: Hello.');

log.length = 0;
ReactDOM.unmountComponentAtNode(container);
expect(log).toEqual([
'ErrorBoundary componentWillUnmount',
]);
});
});