Skip to content

Commit 606adfe

Browse files
committed
fix test
1 parent 9550dbd commit 606adfe

File tree

2 files changed

+34
-23
lines changed

2 files changed

+34
-23
lines changed

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

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3866,13 +3866,12 @@ describe('ReactHooksWithNoopRenderer', () => {
38663866

38673867
ReactNoop.render(<App loadA={true} />);
38683868
expect(() => {
3869-
const expectFlush = expect(() => {
3870-
expect(Scheduler).toFlushAndYield(['A: 0']);
3871-
});
38723869
if (gate(flag => flag.enableThrowOnMountForHookMismatch)) {
3873-
expectFlush.toThrow(
3874-
'Rendered more hooks than during the previous render',
3875-
);
3870+
expect(() => {
3871+
expect(Scheduler).toFlushAndYield(['A: 0']);
3872+
}).toThrow('Rendered more hooks than during the previous render');
3873+
} else {
3874+
expect(Scheduler).toFlushAndYield(['A: 0']);
38763875
}
38773876
}).toErrorDev([
38783877
'Warning: React has detected a change in the order of Hooks called by App. ' +
@@ -3974,24 +3973,34 @@ describe('ReactHooksWithNoopRenderer', () => {
39743973

39753974
act(() => {
39763975
ReactNoop.render(<App showMore={true} />);
3977-
expect(() => {
3978-
const expectFlush = expect(() => {
3976+
if (gate(flags => flags.enableThrowOnMountForHookMismatch)) {
3977+
expect(() => {
3978+
expect(() => {
3979+
expect(Scheduler).toFlushAndYield(['Mount A']);
3980+
}).toThrow('Rendered more hooks than during the previous render');
3981+
}).toErrorDev([
3982+
'Warning: React has detected a change in the order of Hooks called by App. ' +
3983+
'This will lead to bugs and errors if not fixed. For more information, ' +
3984+
'read the Rules of Hooks: https://reactjs.org/link/rules-of-hooks\n\n' +
3985+
' Previous render Next render\n' +
3986+
' ------------------------------------------------------\n' +
3987+
'1. undefined useEffect\n' +
3988+
' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n',
3989+
]);
3990+
} else {
3991+
expect(() => {
39793992
expect(Scheduler).toFlushAndYield(['Mount A']);
3980-
});
3981-
if (gate(flags => flags.enableThrowOnMountForHookMismatch)) {
3982-
expectFlush.toThrow(
3983-
'Rendered more hooks than during the previous render',
3984-
);
3985-
}
3986-
}).toErrorDev([
3987-
'Warning: React has detected a change in the order of Hooks called by App. ' +
3988-
'This will lead to bugs and errors if not fixed. For more information, ' +
3989-
'read the Rules of Hooks: https://reactjs.org/link/rules-of-hooks\n\n' +
3990-
' Previous render Next render\n' +
3991-
' ------------------------------------------------------\n' +
3992-
'1. undefined useEffect\n' +
3993-
' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n',
3994-
]);
3993+
}).toErrorDev([
3994+
'Warning: Internal React error: Expected static flag was missing. Please notify the React team.',
3995+
'Warning: React has detected a change in the order of Hooks called by App. ' +
3996+
'This will lead to bugs and errors if not fixed. For more information, ' +
3997+
'read the Rules of Hooks: https://reactjs.org/link/rules-of-hooks\n\n' +
3998+
' Previous render Next render\n' +
3999+
' ------------------------------------------------------\n' +
4000+
'1. undefined useEffect\n' +
4001+
' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n',
4002+
]);
4003+
}
39954004
});
39964005
});
39974006

packages/shared/forks/ReactFeatureFlags.test-renderer.native.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ export const enableUseMutableSource = false;
7070
export const enableTransitionTracing = false;
7171

7272
export const enableFloat = false;
73+
74+
export const enableThrowOnMountForHookMismatch = false;
7375
// Flow magic to verify the exports of this file match the original version.
7476
// eslint-disable-next-line no-unused-vars
7577
type Check<_X, Y: _X, X: Y = _X> = null;

0 commit comments

Comments
 (0)