Skip to content

Commit 8a72a34

Browse files
authored
[code-infra] Move the shared spy helpers off Sinon (#23466)
1 parent ce5021f commit 8a72a34

11 files changed

Lines changed: 766 additions & 746 deletions

File tree

packages/x-data-grid-premium/src/tests/cellSelection.DataGridPremium.test.tsx

Lines changed: 75 additions & 75 deletions
Large diffs are not rendered by default.

packages/x-data-grid-premium/src/tests/exportExcel.DataGridPremium.test.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@ import type {
88
GridFormulaFunctionDefinition,
99
} from '@mui/x-data-grid-premium';
1010
import { createRenderer, screen, act } from '@mui/internal-test-utils';
11-
import { spy } from 'sinon';
12-
import type { SinonSpy } from 'sinon';
1311
import Excel from '@mui/x-internal-exceljs-fork';
1412
import { spyApi } from 'test/utils/helperFn';
15-
import { describe, it, expect, beforeEach } from 'vitest';
13+
import { vi, describe, it, expect, beforeEach } from 'vitest';
14+
import type { Mock } from 'vitest';
1615

1716
const isJSDOM = /jsdom/.test(window.navigator.userAgent);
1817

@@ -699,25 +698,25 @@ describe('<DataGridPremium /> - Export Excel', () => {
699698
});
700699

701700
describe('web worker', () => {
702-
let workerMock: { postMessage: SinonSpy };
701+
let workerMock: { postMessage: Mock };
703702

704703
beforeEach(() => {
705704
workerMock = {
706-
postMessage: spy(),
705+
postMessage: vi.fn(),
707706
};
708707
});
709708

710709
it('should not call getDataAsExcel', async () => {
711710
render(<TestCaseExcelExport />);
712711
const getDataAsExcelSpy = spyApi(apiRef.current!, 'getDataAsExcel');
713712
await act(() => apiRef.current?.exportDataAsExcel({ worker: () => workerMock as any }));
714-
expect(getDataAsExcelSpy.calledOnce).to.equal(false);
713+
expect(getDataAsExcelSpy.mock.calls.length).to.equal(0);
715714
});
716715

717716
it('should post a message to the web worker with the serialized columns', async () => {
718717
render(<TestCaseExcelExport />);
719718
await act(() => apiRef.current?.exportDataAsExcel({ worker: () => workerMock as any }));
720-
expect(workerMock.postMessage.lastCall.args[0].serializedColumns).to.deep.equal([
719+
expect(workerMock.postMessage.mock.lastCall?.[0].serializedColumns).to.deep.equal([
721720
{ key: 'id', headerText: 'id', style: {}, width: 100 / 7.5 },
722721
{ key: 'brand', headerText: 'Brand', style: {}, width: 100 / 7.5 },
723722
]);
@@ -726,7 +725,7 @@ describe('<DataGridPremium /> - Export Excel', () => {
726725
it('should post a message to the web worker with the serialized rows', async () => {
727726
render(<TestCaseExcelExport />);
728727
await act(() => apiRef.current?.exportDataAsExcel({ worker: () => workerMock as any }));
729-
expect(workerMock.postMessage.lastCall.args[0].serializedRows).to.deep.equal([
728+
expect(workerMock.postMessage.mock.lastCall?.[0].serializedRows).to.deep.equal([
730729
{
731730
dataValidation: {},
732731
mergedCells: [],
@@ -774,7 +773,8 @@ describe('<DataGridPremium /> - Export Excel', () => {
774773
escapeFormulas: false,
775774
}),
776775
);
777-
const { serializedRows } = workerMock.postMessage.lastCall.args[0];
776+
expect(workerMock.postMessage.mock.calls.length).to.equal(1);
777+
const { serializedRows } = workerMock.postMessage.mock.lastCall?.[0] ?? {};
778778
expect(serializedRows[0].formulas).to.deep.equal({
779779
total: { formula: 'A2*B2', result: 20 },
780780
});

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

Lines changed: 176 additions & 176 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)