Skip to content

Commit

Permalink
Keep log assertions small
Browse files Browse the repository at this point in the history
The longer the list of log lines asserted one, the harder future diffs are to comprehend.
git-diff produces hard to decipher diffs if the StrictEffects behavior is changed slightly that results in more lines added.
It won't be obvious anymore which lines were added and which ones were removed.
  • Loading branch information
eps1lon committed May 20, 2024
1 parent 17e94fe commit 686bed8
Showing 1 changed file with 22 additions and 35 deletions.
57 changes: 22 additions & 35 deletions packages/react-reconciler/src/__tests__/StrictEffectsMode-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -900,8 +900,17 @@ describe('StrictEffectsMode', () => {
);
});

expect(log).toEqual([
'Parent rendered',
'Parent rendered',
'Child rendered',
'Child suspended',
'Fallback',
'Fallback',
]);

log = [];
// while suspended, update
log.push('-----------------------after update');
await act(() => {
ReactNoop.render(
<React.StrictMode>
Expand All @@ -910,32 +919,26 @@ describe('StrictEffectsMode', () => {
);
});

// Now resolve and commit
log.push('-----------------------after suspense');
expect(log).toEqual([
'Parent rendered',
'Parent rendered',
'Child rendered',
'Child suspended',
'Fallback',
'Fallback',
'Parent dep destroy',
'Parent dep create',
]);

log = [];
// Now resolve and commit
await act(() => {
resolve();
shouldSuspend = false;
});

if (gate(flags => flags.useModernStrictMode)) {
expect(log).toEqual([
'Parent rendered',
'Parent rendered',
'Child rendered',
'Child suspended',
'Fallback',
'Fallback',
'-----------------------after update',
'Parent rendered',
'Parent rendered',
'Child rendered',
'Child suspended',
'Fallback',
'Fallback',
'Parent dep destroy',
'Parent dep create',
'-----------------------after suspense',
'Child rendered',
'Child rendered',
// !!! Committed, destroy and create effect.
Expand All @@ -957,22 +960,6 @@ describe('StrictEffectsMode', () => {
]);
} else {
expect(log).toEqual([
'Parent rendered',
'Parent rendered',
'Child rendered',
'Child suspended',
'Fallback',
'Fallback',
'-----------------------after update',
'Parent rendered',
'Parent rendered',
'Child rendered',
'Child suspended',
'Fallback',
'Fallback',
'Parent dep destroy',
'Parent dep create',
'-----------------------after suspense',
'Child rendered',
'Child rendered',
'Child dep destroy',
Expand Down

0 comments on commit 686bed8

Please sign in to comment.