Skip to content

Commit

Permalink
[test] Fix DataGrid data source error test on React 18 (#16565)
Browse files Browse the repository at this point in the history
  • Loading branch information
arminmeh authored Feb 13, 2025
1 parent 6b4fdc8 commit 3dca3e1
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions packages/x-data-grid-pro/src/tests/dataSource.DataGridPro.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -277,26 +277,22 @@ describeSkipIf(isJSDOM)('<DataGridPro /> - Data source', () => {

describe('Error handling', () => {
it('should call `unstable_onDataSourceError` when the data source returns an error', async () => {
const onDataSourceError = spy();

const dataSource: GridDataSource = {
getRows: () => {
throw new Error('Could not fetch the data');
},
};

render(
<div style={{ width: 300, height: 300 }}>
<DataGridPro
columns={[]}
unstable_dataSource={dataSource}
unstable_onDataSourceError={onDataSourceError}
/>
</div>,
const onDataSourceErrorSpy = spy();
const { setProps } = render(
<TestDataSource
unstable_dataSourceCache={null}
unstable_onDataSourceError={onDataSourceErrorSpy}
/>,
);
expect(onDataSourceErrorSpy.callCount).to.equal(0);

setProps({ shouldRequestsFail: true });
act(() => {
apiRef.current.unstable_dataSource.fetchRows();
});

await waitFor(() => {
expect(onDataSourceError.callCount).to.equal(1);
expect(onDataSourceErrorSpy.callCount).to.equal(1);
});
});
});
Expand Down

0 comments on commit 3dca3e1

Please sign in to comment.