Skip to content
This repository was archived by the owner on Jan 1, 2025. It is now read-only.

Commit 46bb471

Browse files
acdlitefacebook-github-bot
authored andcommitted
React sync for revisions 568dc35...27c9c95
Summary: Includes a re-implementation of the `act` testing API to decouple it from the mock Scheduler module. Because our Jest configuration mocks the Scheduler for all tests in www, some tests had become accidentally coupled to it. I had to update ~60 test files. The most common pattern I found was people calling `act()` with a no-op function, which had the effect of flushing all pending work. This no longer works in the new implementation. (We will eventually provide a way to opt into Scheduler mocking for advanced cases, but it probably won't be the default.) The fix was usually to wrap an earlier update in `act` to ensure that all its work is fully flushed. --- This sync includes the following changes: - **[27c9c95e2](facebook/react@27c9c95e2)**: act: Bypass microtask for "default sync" updates ([#21740](facebook/react#21740)) //<Andrew Clark>// - **[e577bfb1c](facebook/react@e577bfb1c)**: Add tests for invokeGuardedCallback ([#21734](facebook/react#21734)) //<Dan Abramov>// - **[355591add](facebook/react@355591add)**: Next/experimental release versions include commit date ([#21700](facebook/react#21700)) //<Brian Vaughn>// - **[d7dce572c](facebook/react@d7dce572c)**: Remove internal `act` builds from public modules ([#21721](facebook/react#21721)) //<Andrew Clark>// - **[06f7b4f43](facebook/react@06f7b4f43)**: `act` should work without mock Scheduler ([#21714](facebook/react#21714)) //<Andrew Clark>// - **[422e0bb36](facebook/react@422e0bb36)**: Delete test-utils implementation of `act` ([#21703](facebook/react#21703)) //<Andrew Clark>// Reviewed By: rickhanlonii Differential Revision: D29314763 fbshipit-source-id: 6c53a053e00defee0ab89f30e2f6bd2a1ff29bce
1 parent be6fdaf commit 46bb471

File tree

2 files changed

+46
-39
lines changed

2 files changed

+46
-39
lines changed

src/contrib/uri_persistence/__tests__/Recoil_Link-test.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ test('Link - snapshot', async () => {
7171
'https://test.com/test?atom=%22MAP',
7272
);
7373

74-
Simulate.click(c.children[0], {button: 0});
74+
act(() => {
75+
Simulate.click(c.children[0], {button: 0});
76+
});
7577
await flushPromisesAndTimers();
7678
expect(c.textContent).toEqual('"MAP"LINK-MAP');
7779
});
@@ -95,7 +97,9 @@ test('Link - stateChange', async () => {
9597
'https://test.com/test?atom=%22MAP',
9698
);
9799

98-
Simulate.click(c.children[0], {button: 0});
100+
act(() => {
101+
Simulate.click(c.children[0], {button: 0});
102+
});
99103
await flushPromisesAndTimers();
100104
expect(c.textContent).toEqual('"MAP"LINK');
101105
});
@@ -120,7 +124,9 @@ test('Link - state update', async () => {
120124
'https://test.com/test?atom=%22MAP%20SET',
121125
);
122126

123-
Simulate.click(c.children[0], {button: 0});
127+
act(() => {
128+
Simulate.click(c.children[0], {button: 0});
129+
});
124130
await flushPromisesAndTimers();
125131
expect(c.textContent).toEqual('"MAP SET"LINK');
126132
});

src/hooks/__tests__/Recoil_useRecoilBridgeAcrossReactRoots-test.js

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -36,52 +36,53 @@ const testRecoil = getRecoilTestFn(() => {
3636
useRecoilBridgeAcrossReactRoots = require('../Recoil_useRecoilBridgeAcrossReactRoots');
3737
});
3838

39-
testRecoil('useRecoilBridgeAcrossReactRoots - create a context bridge', () => {
40-
const myAtom = atom({
41-
key: 'useRecoilBridgeAcrossReactRoots - context bridge',
42-
default: 'DEFAULT',
43-
});
39+
testRecoil(
40+
'useRecoilBridgeAcrossReactRoots - create a context bridge',
41+
async () => {
42+
const myAtom = atom({
43+
key: 'useRecoilBridgeAcrossReactRoots - context bridge',
44+
default: 'DEFAULT',
45+
});
4446

45-
function initializeState({set, getLoadable}) {
46-
expect(getLoadable(myAtom).contents).toEqual('DEFAULT');
47-
set(myAtom, 'INITIALIZE');
48-
expect(getLoadable(myAtom).contents).toEqual('INITIALIZE');
49-
}
47+
function initializeState({set, getLoadable}) {
48+
expect(getLoadable(myAtom).contents).toEqual('DEFAULT');
49+
set(myAtom, 'INITIALIZE');
50+
expect(getLoadable(myAtom).contents).toEqual('INITIALIZE');
51+
}
5052

51-
const [ReadWriteAtom, setAtom] = componentThatReadsAndWritesAtom(myAtom);
53+
const [ReadWriteAtom, setAtom] = componentThatReadsAndWritesAtom(myAtom);
5254

53-
function NestedReactRoot({children}) {
54-
const ref = useRef();
55-
const RecoilBridge = useRecoilBridgeAcrossReactRoots();
55+
function NestedReactRoot({children}) {
56+
const ref = useRef();
57+
const RecoilBridge = useRecoilBridgeAcrossReactRoots();
5658

57-
useEffect(() => {
58-
act(() => {
59+
useEffect(() => {
5960
ReactDOM.render(
6061
<RecoilBridge>{children}</RecoilBridge>,
6162
ref.current ?? document.createElement('div'),
6263
);
63-
});
64-
}, [children]);
64+
}, [children]);
6565

66-
return <div ref={ref} />;
67-
}
66+
return <div ref={ref} />;
67+
}
6868

69-
const container = document.createElement('div');
70-
act(() => {
71-
ReactDOM.render(
72-
<RecoilRoot initializeState={initializeState}>
73-
<ReadWriteAtom />
74-
75-
<NestedReactRoot>
69+
const container = document.createElement('div');
70+
await act(() => {
71+
ReactDOM.render(
72+
<RecoilRoot initializeState={initializeState}>
7673
<ReadWriteAtom />
77-
</NestedReactRoot>
78-
</RecoilRoot>,
79-
container,
80-
);
81-
});
8274

83-
expect(container.textContent).toEqual('"INITIALIZE""INITIALIZE"');
75+
<NestedReactRoot>
76+
<ReadWriteAtom />
77+
</NestedReactRoot>
78+
</RecoilRoot>,
79+
container,
80+
);
81+
});
8482

85-
act(() => setAtom('SET'));
86-
expect(container.textContent).toEqual('"SET""SET"');
87-
});
83+
expect(container.textContent).toEqual('"INITIALIZE""INITIALIZE"');
84+
85+
act(() => setAtom('SET'));
86+
expect(container.textContent).toEqual('"SET""SET"');
87+
},
88+
);

0 commit comments

Comments
 (0)