From 679f6288e1ec1dd5f7513b3d7ec53b6805998bf9 Mon Sep 17 00:00:00 2001 From: Armin Mehinovic Date: Thu, 9 Jan 2025 13:34:32 +0100 Subject: [PATCH] Fix tests --- .../dataSourceLazyLoader.DataGridPro.test.tsx | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/packages/x-data-grid-pro/src/tests/dataSourceLazyLoader.DataGridPro.test.tsx b/packages/x-data-grid-pro/src/tests/dataSourceLazyLoader.DataGridPro.test.tsx index ba2284332da05..0e8daf15e654a 100644 --- a/packages/x-data-grid-pro/src/tests/dataSourceLazyLoader.DataGridPro.test.tsx +++ b/packages/x-data-grid-pro/src/tests/dataSourceLazyLoader.DataGridPro.test.tsx @@ -228,6 +228,11 @@ describeSkipIf(isJSDOM)(' - Data source lazy loader', () => { apiRef.current.scrollToIndexes({ rowIndex: 9 }); + // wait until the debounced fetch + await waitFor(() => { + expect(fetchRowsSpy.callCount).to.equal(2); + }); + // wait until the rows are rendered await waitFor(() => expect(getRow(10)).not.to.be.undefined); @@ -237,6 +242,10 @@ describeSkipIf(isJSDOM)(' - Data source lazy loader', () => { apiRef.current.sortColumn(mockServer.columns[0].field, 'asc'); + await waitFor(() => { + expect(fetchRowsSpy.callCount).to.equal(3); + }); + const afterSortingSearchParams = new URL(fetchRowsSpy.lastCall.args[0]).searchParams; // last row is the end of the first page expect(afterSortingSearchParams.get('end')).to.equal('9'); @@ -249,6 +258,11 @@ describeSkipIf(isJSDOM)(' - Data source lazy loader', () => { apiRef.current.scrollToIndexes({ rowIndex: 9 }); + // wait until the debounced fetch + await waitFor(() => { + expect(fetchRowsSpy.callCount).to.equal(2); + }); + // wait until the rows are rendered await waitFor(() => expect(getRow(10)).not.to.be.undefined); @@ -266,6 +280,10 @@ describeSkipIf(isJSDOM)(' - Data source lazy loader', () => { ], }); + await waitFor(() => { + expect(fetchRowsSpy.callCount).to.equal(3); + }); + const afterFilteringSearchParams = new URL(fetchRowsSpy.lastCall.args[0]).searchParams; // last row is the end of the first page expect(afterFilteringSearchParams.get('end')).to.equal('9'); @@ -287,7 +305,9 @@ describeSkipIf(isJSDOM)(' - Data source lazy loader', () => { setProps({ rowCount: 100 }); // The 11th row should be a skeleton - expect(getRow(10).dataset.id).to.equal('auto-generated-skeleton-row-root-10'); + await waitFor(() => + expect(getRow(10).dataset.id).to.equal('auto-generated-skeleton-row-root-10'), + ); }); it('should reset the grid if the rowCount becomes unknown', async () => {