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

[tests] assertLog before act in ReactCompositeComponentState #28758

Merged
merged 1 commit into from
Apr 10, 2024
Merged
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -152,21 +152,6 @@ describe('ReactCompositeComponent-state', () => {
root.render(<TestComponent />);
});

await act(() => {
root.render(<TestComponent nextColor="green" />);
});

await act(() => {
testComponentInstance.setFavoriteColor('blue');
});
await act(() => {
testComponentInstance.forceUpdate(
testComponentInstance.peekAtCallback('forceUpdate'),
);
});

root.unmount();

assertLog([
// there is no state when getInitialState() is called
'getInitialState undefined',
Expand Down Expand Up @@ -198,6 +183,13 @@ describe('ReactCompositeComponent-state', () => {
'componentDidUpdate-prevState orange',
'setState-yellow yellow',
'commit yellow',
]);

await act(() => {
root.render(<TestComponent nextColor="green" />);
});

assertLog([
'componentWillReceiveProps-start yellow',
// setState({color:'green'}) only enqueues a pending state.
'componentWillReceiveProps-end yellow',
Expand All @@ -216,6 +208,13 @@ describe('ReactCompositeComponent-state', () => {
'componentDidUpdate-prevState yellow',
'setState-receiveProps green',
'commit green',
]);

await act(() => {
testComponentInstance.setFavoriteColor('blue');
});

assertLog([
// setFavoriteColor('blue')
'shouldComponentUpdate-currentState green',
'shouldComponentUpdate-nextState blue',
Expand All @@ -226,6 +225,13 @@ describe('ReactCompositeComponent-state', () => {
'componentDidUpdate-prevState green',
'setFavoriteColor blue',
'commit blue',
]);
await act(() => {
testComponentInstance.forceUpdate(
testComponentInstance.peekAtCallback('forceUpdate'),
);
});
assertLog([
// forceUpdate()
'componentWillUpdate-currentState blue',
'componentWillUpdate-nextState blue',
Expand All @@ -234,7 +240,12 @@ describe('ReactCompositeComponent-state', () => {
'componentDidUpdate-prevState blue',
'forceUpdate blue',
'commit blue',
// unmountComponent()
]);

root.unmount();

assertLog([
// unmount()
// state is available within `componentWillUnmount()`
'componentWillUnmount blue',
]);
Expand Down Expand Up @@ -375,13 +386,13 @@ describe('ReactCompositeComponent-state', () => {
await act(() => {
root.render(<Parent />);
});

assertLog(['parent render one', 'child render one']);
await act(() => {
root.render(<Parent />);
});

assertLog([
'parent render one',
'child render one',
'parent render one',
'child componentWillReceiveProps one',
'child componentWillReceiveProps done one',
Expand Down