Skip to content

Commit 03a9fc8

Browse files
committed
Use previous "root"-approach
Tests should now be invariant under variants
1 parent 6ab57a8 commit 03a9fc8

1 file changed

Lines changed: 7 additions & 18 deletions

File tree

packages/react-reconciler/src/__tests__/ReactHooksWithNoopRenderer-test.js

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2641,42 +2641,31 @@ describe('ReactHooksWithNoopRenderer', () => {
26412641
return null;
26422642
}
26432643

2644+
const root1 = ReactNoop.createRoot();
26442645
expect(() =>
26452646
act(() => {
2646-
ReactNoop.render(<App return={17} />);
2647+
root1.render(<App return={17} />);
26472648
}),
26482649
).toErrorDev([
26492650
'Warning: An effect function must not return anything besides a ' +
26502651
'function, which is used for clean-up. You returned: 17',
26512652
]);
26522653

2653-
// Error on unmount because React assumes the value is a function
2654-
expect(() =>
2655-
act(() => {
2656-
ReactNoop.render(null);
2657-
}),
2658-
).toThrow('is not a function');
2659-
2654+
const root2 = ReactNoop.createRoot();
26602655
expect(() =>
26612656
act(() => {
2662-
ReactNoop.render(<App return={null} />);
2657+
root2.render(<App return={null} />);
26632658
}),
26642659
).toErrorDev([
26652660
'Warning: An effect function must not return anything besides a ' +
26662661
'function, which is used for clean-up. You returned null. If your ' +
26672662
'effect does not require clean up, return undefined (or nothing).',
26682663
]);
26692664

2670-
// Error on unmount because React assumes the value is a function
2671-
expect(() =>
2672-
act(() => {
2673-
ReactNoop.render(null);
2674-
}),
2675-
).toThrow('is not a function');
2676-
2665+
const root3 = ReactNoop.createRoot();
26772666
expect(() =>
26782667
act(() => {
2679-
ReactNoop.render(<App return={Promise.resolve()} />);
2668+
root3.render(<App return={Promise.resolve()} />);
26802669
}),
26812670
).toErrorDev([
26822671
'Warning: An effect function must not return anything besides a ' +
@@ -2687,7 +2676,7 @@ describe('ReactHooksWithNoopRenderer', () => {
26872676
// Error on unmount because React assumes the value is a function
26882677
expect(() =>
26892678
act(() => {
2690-
ReactNoop.render(null);
2679+
root3.unmount();
26912680
}),
26922681
).toThrow('is not a function');
26932682
});

0 commit comments

Comments
 (0)