Skip to content

Commit ceb4d1c

Browse files
committed
Test: Deletion effects should fire parent -> child
Regression in new effect implementation
1 parent e6ed2bc commit ceb4d1c

File tree

1 file changed

+86
-0
lines changed

1 file changed

+86
-0
lines changed
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @emails react-core
8+
* @jest-environment node
9+
*/
10+
11+
/* eslint-disable no-func-assign */
12+
13+
'use strict';
14+
15+
let React;
16+
let ReactNoop;
17+
let Scheduler;
18+
let useEffect;
19+
let useLayoutEffect;
20+
21+
describe('ReactHooksWithNoopRenderer', () => {
22+
beforeEach(() => {
23+
jest.resetModules();
24+
jest.useFakeTimers();
25+
26+
React = require('react');
27+
ReactNoop = require('react-noop-renderer');
28+
Scheduler = require('scheduler');
29+
useEffect = React.useEffect;
30+
useLayoutEffect = React.useLayoutEffect;
31+
});
32+
33+
test('layout unmmouts on deletion are fired in parent -> child order', async () => {
34+
const root = ReactNoop.createRoot();
35+
36+
function Parent() {
37+
useLayoutEffect(() => {
38+
return () => Scheduler.unstable_yieldValue('Unmount parent');
39+
});
40+
return <Child />;
41+
}
42+
43+
function Child() {
44+
useLayoutEffect(() => {
45+
return () => Scheduler.unstable_yieldValue('Unmount child');
46+
});
47+
return 'Child';
48+
}
49+
50+
await ReactNoop.act(async () => {
51+
root.render(<Parent />);
52+
});
53+
expect(root).toMatchRenderedOutput('Child');
54+
await ReactNoop.act(async () => {
55+
root.render(null);
56+
});
57+
expect(Scheduler).toHaveYielded(['Unmount parent', 'Unmount child']);
58+
});
59+
60+
test('passive unmmouts on deletion are fired in parent -> child order', async () => {
61+
const root = ReactNoop.createRoot();
62+
63+
function Parent() {
64+
useEffect(() => {
65+
return () => Scheduler.unstable_yieldValue('Unmount parent');
66+
});
67+
return <Child />;
68+
}
69+
70+
function Child() {
71+
useEffect(() => {
72+
return () => Scheduler.unstable_yieldValue('Unmount child');
73+
});
74+
return 'Child';
75+
}
76+
77+
await ReactNoop.act(async () => {
78+
root.render(<Parent />);
79+
});
80+
expect(root).toMatchRenderedOutput('Child');
81+
await ReactNoop.act(async () => {
82+
root.render(null);
83+
});
84+
expect(Scheduler).toHaveYielded(['Unmount parent', 'Unmount child']);
85+
});
86+
});

0 commit comments

Comments
 (0)