Skip to content

Commit 553d237

Browse files
authored
[test] Fix act warnings in the data source filter tests (#23360)
1 parent 7b70c2f commit 553d237

5 files changed

Lines changed: 21 additions & 14 deletions

File tree

packages/x-data-grid-pro/src/tests/dataSource.DataGridPro.test.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import type {
1212
GridLogicOperator,
1313
} from '@mui/x-data-grid-pro';
1414
import { spy } from 'sinon';
15-
import { getRow, sleep } from 'test/utils/helperFn';
15+
import { actSleep, getRow } from 'test/utils/helperFn';
1616
import { TestCache } from '@mui/x-data-grid/internals';
1717

1818
describe('<DataGridPro /> - Data source', () => {
@@ -99,7 +99,7 @@ describe('<DataGridPro /> - Data source', () => {
9999
});
100100

101101
await upsertFilterItem({ id: 2, field: 'id', operator: 'contains' });
102-
await sleep(50);
102+
await actSleep(50);
103103

104104
expect(fetchRowsSpy.callCount).to.equal(2);
105105
expect(fetchRowsSpy.lastCall.args[0].filterModel.items).to.have.length(1);
@@ -143,7 +143,7 @@ describe('<DataGridPro /> - Data source', () => {
143143
await act(async () => {
144144
apiRef.current!.setFilterLogicOperator('or' as GridLogicOperator);
145145
});
146-
await sleep(50);
146+
await actSleep(50);
147147

148148
expect(fetchRowsSpy.callCount).to.equal(2);
149149
});
@@ -163,7 +163,7 @@ describe('<DataGridPro /> - Data source', () => {
163163
await act(async () => {
164164
apiRef.current!.setFilterLogicOperator('or' as GridLogicOperator);
165165
});
166-
await sleep(50);
166+
await actSleep(50);
167167
expect(fetchRowsSpy.callCount).to.equal(2);
168168

169169
await upsertFilterItem({ id: 2, field: 'id', operator: 'contains', value: '2' });

packages/x-data-grid-pro/src/tests/dataSourceLazyLoader.DataGridPro.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as React from 'react';
22
import { useMockServer } from '@mui/x-data-grid-generator';
33
import { act, createRenderer, waitFor, within } from '@mui/internal-test-utils';
4-
import { getCell, getRow, sleep } from 'test/utils/helperFn';
4+
import { actSleep, getCell, getRow } from 'test/utils/helperFn';
55
import type { RefObject } from '@mui/x-internals/types';
66
import { DataGridPro, useGridApiRef, GRID_ROOT_GROUP_ID } from '@mui/x-data-grid-pro';
77
import type {
@@ -170,7 +170,7 @@ describe.skipIf(isJSDOM)('<DataGridPro /> - Data source lazy loader', () => {
170170
});
171171

172172
await upsertFilterItem({ id: 1, field: 'id', operator: 'contains' });
173-
await sleep(50);
173+
await actSleep(50);
174174

175175
expect(fetchRowsSpy.callCount).to.equal(1);
176176
});

packages/x-data-grid-pro/src/tests/dataSourceTreeData.DataGridPro.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import type {
1212
GridGroupNode,
1313
} from '@mui/x-data-grid-pro';
1414
import { spy } from 'sinon';
15-
import { getCell, getRow, sleep } from 'test/utils/helperFn';
15+
import { actSleep, getCell, getRow } from 'test/utils/helperFn';
1616
import { isJSDOM } from 'test/utils/skipIf';
1717

1818
const dataSetOptions = {
@@ -180,7 +180,7 @@ describe.skipIf(isJSDOM)('<DataGridPro /> - Data source tree data', () => {
180180
await act(async () => {
181181
apiRef.current!.upsertFilterItem({ id: 1, field: 'name', operator: 'contains' });
182182
});
183-
await sleep(50);
183+
await actSleep(50);
184184

185185
expect(fetchRowsSpy.callCount).to.equal(1);
186186
});

packages/x-data-grid/src/tests/dataSource.DataGrid.test.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import type {
1313
GridGetRowsResponse,
1414
} from '@mui/x-data-grid';
1515
import { spy } from 'sinon';
16-
import { getCell, sleep } from 'test/utils/helperFn';
16+
import { actSleep, getCell } from 'test/utils/helperFn';
1717
import { getKeyDefault } from '../hooks/features/dataSource/cache';
1818
import { TestCache } from '../internals/utils';
1919

@@ -235,7 +235,7 @@ describe('<DataGrid /> - Data source', () => {
235235
await renderAndWaitForInitialFetch();
236236

237237
await upsertFilterItem({ id: 1, field: 'id', operator: 'contains' });
238-
await sleep(50);
238+
await actSleep(50);
239239

240240
expect(fetchRowsSpy.callCount).to.equal(1);
241241
});
@@ -244,7 +244,7 @@ describe('<DataGrid /> - Data source', () => {
244244
await renderAndWaitForInitialFetch();
245245

246246
await upsertFilterItem({ id: 1, field: 'id', operator: 'contains' });
247-
await sleep(50);
247+
await actSleep(50);
248248
expect(fetchRowsSpy.callCount).to.equal(1);
249249

250250
await upsertFilterItem({ id: 1, field: 'id', operator: 'contains', value: '1' });
@@ -280,7 +280,7 @@ describe('<DataGrid /> - Data source', () => {
280280
await act(async () => {
281281
apiRef.current!.setFilterLogicOperator('or' as GridLogicOperator);
282282
});
283-
await sleep(50);
283+
await actSleep(50);
284284

285285
expect(fetchRowsSpy.callCount).to.equal(2);
286286
});
@@ -291,7 +291,7 @@ describe('<DataGrid /> - Data source', () => {
291291
await act(async () => {
292292
apiRef.current!.setQuickFilterValues(['']);
293293
});
294-
await sleep(50);
294+
await actSleep(50);
295295

296296
expect(fetchRowsSpy.callCount).to.equal(1);
297297
});
@@ -312,7 +312,7 @@ describe('<DataGrid /> - Data source', () => {
312312
quickFilterLogicOperator: 'or' as GridLogicOperator,
313313
});
314314
});
315-
await sleep(50);
315+
await actSleep(50);
316316

317317
expect(fetchRowsSpy.callCount).to.equal(2);
318318
});

test/utils/helperFn.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ export function microtasks() {
5050
return act(() => Promise.resolve()) as unknown as Promise<void>;
5151
}
5252

53+
// `sleep` inside `act`, so updates settling during the wait don't warn about missing `act`.
54+
export async function actSleep(duration: number) {
55+
await act(async () => {
56+
await sleep(duration);
57+
});
58+
}
59+
5360
export function spyApi(api: GridApiCommon, methodName: string) {
5461
const methodKey = methodName as keyof GridApiCommon;
5562
const privateApi = unwrapPrivateAPI(api);

0 commit comments

Comments
 (0)