Skip to content

Commit 5035ddc

Browse files
committed
Add failing test
1 parent 94c4f8a commit 5035ddc

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
'use strict';
1414

15+
import {useInsertionEffect} from 'react';
16+
1517
describe('useRef', () => {
1618
let React;
1719
let ReactNoop;
@@ -403,4 +405,37 @@ describe('useRef', () => {
403405
span('Count: 34'),
404406
]);
405407
});
408+
409+
it('is mutated before all other effects', () => {
410+
function Counter({value}) {
411+
useInsertionEffect(() => {
412+
Scheduler.unstable_yieldValue('Effect value: ' + value);
413+
increment();
414+
}, [value]);
415+
416+
// This is defined after the insertion effect, but it should
417+
// update the event fn _before_ the insertion effect fires.
418+
const increment = useEvent(() => {
419+
Scheduler.unstable_yieldValue('Event value: ' + value);
420+
});
421+
422+
return (
423+
<>
424+
</>
425+
);
426+
}
427+
428+
ReactNoop.render(<Counter value={1} />);
429+
expect(Scheduler).toFlushAndYield([
430+
'Effect value: 1',
431+
'Event value: 1',
432+
]);
433+
434+
435+
act(() => ReactNoop.render(<Counter value={2} />));
436+
expect(Scheduler).toHaveYielded([
437+
'Effect value: 2',
438+
'Event value: 2',
439+
]);
440+
});
406441
});

0 commit comments

Comments
 (0)