Skip to content

Commit

Permalink
Codemod act -> await act (4/?) (#26338)
Browse files Browse the repository at this point in the history
Similar to the rationale for `waitFor` (see #26285), we should always
await the result of an `act` call so that microtasks have a chance to
fire.

This only affects the internal `act` that we use in our repo, for now.
In the public `act` API, we don't yet require this; however, we
effectively will for any update that triggers suspense once `use` lands.
So we likely will start warning in an upcoming minor.
  • Loading branch information
acdlite authored Mar 8, 2023
1 parent 9fb2469 commit 702fc98
Show file tree
Hide file tree
Showing 18 changed files with 907 additions and 1,075 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -984,7 +984,7 @@ describe('ReactHooksInspectionIntegration', () => {
children: ['count: ', '1'],
});

act(incrementCount);
await act(async () => incrementCount());
expect(renderer.toJSON()).toEqual({
type: 'div',
props: {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1069,8 +1069,8 @@ describe('InspectedElement', () => {
});

async function loadPath(path) {
TestUtilsAct(() => {
TestRendererAct(() => {
await TestUtilsAct(async () => {
await TestRendererAct(async () => {
inspectElementPath(path);
jest.runOnlyPendingTimers();
});
Expand Down Expand Up @@ -1224,8 +1224,8 @@ describe('InspectedElement', () => {
});

async function loadPath(path) {
TestUtilsAct(() => {
TestRendererAct(() => {
await TestUtilsAct(async () => {
await TestRendererAct(async () => {
inspectElementPath(path);
jest.runOnlyPendingTimers();
});
Expand Down Expand Up @@ -1306,8 +1306,8 @@ describe('InspectedElement', () => {
});

async function loadPath(path) {
TestUtilsAct(() => {
TestRendererAct(() => {
await TestUtilsAct(async () => {
await TestRendererAct(async () => {
inspectElementPath(path);
jest.runOnlyPendingTimers();
});
Expand Down Expand Up @@ -1375,8 +1375,8 @@ describe('InspectedElement', () => {
}
`);

TestRendererAct(() => {
TestUtilsAct(() => {
await TestRendererAct(async () => {
await TestUtilsAct(async () => {
legacyRender(
<Example
nestedObject={{
Expand Down Expand Up @@ -1469,8 +1469,8 @@ describe('InspectedElement', () => {
});

async function loadPath(path) {
TestUtilsAct(() => {
TestRendererAct(() => {
await TestUtilsAct(async () => {
await TestRendererAct(async () => {
inspectElementPath(path);
jest.runOnlyPendingTimers();
});
Expand Down Expand Up @@ -1513,8 +1513,8 @@ describe('InspectedElement', () => {
}
`);

TestRendererAct(() => {
TestUtilsAct(() => {
await TestRendererAct(async () => {
await TestUtilsAct(async () => {
legacyRender(
<Example
nestedObject={{
Expand Down Expand Up @@ -1596,8 +1596,8 @@ describe('InspectedElement', () => {
});

async function loadPath(path) {
TestUtilsAct(() => {
TestRendererAct(() => {
await TestUtilsAct(async () => {
await TestRendererAct(async () => {
inspectElementPath(path);
jest.runOnlyPendingTimers();
});
Expand All @@ -1618,7 +1618,7 @@ describe('InspectedElement', () => {
}
`);

TestUtilsAct(() => {
await TestUtilsAct(async () => {
legacyRender(
<Example
nestedObject={{
Expand All @@ -1640,11 +1640,9 @@ describe('InspectedElement', () => {
expect(inspectedElement.props).toMatchInlineSnapshot(`
{
"nestedObject": {
"a": {
"b": {
"value": 2,
},
"value": 2,
"a": Dehydrated {
"preview_short": {…},
"preview_long": {b: {…}, value: 2},
},
"value": 2,
},
Expand Down Expand Up @@ -2833,7 +2831,7 @@ describe('InspectedElement', () => {
};
const toggleError = async forceError => {
await withErrorsOrWarningsIgnored(['ErrorBoundary'], async () => {
await TestUtilsAct(() => {
await TestUtilsAct(async () => {
bridge.send('overrideError', {
id: targetErrorBoundaryID,
rendererID: store.getRendererIDForElement(targetErrorBoundaryID),
Expand All @@ -2842,7 +2840,7 @@ describe('InspectedElement', () => {
});
});

TestUtilsAct(() => {
await TestUtilsAct(async () => {
jest.runOnlyPendingTimers();
});
};
Expand Down
Loading

0 comments on commit 702fc98

Please sign in to comment.