Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 25, 2025

Cherry-picks changes from #20352 to migrate x-charts packages from sinon to Vitest mocking utilities.

Changes

  • Replace spy() / sinon.spy() with vi.fn()
  • Replace .callCount with .mock.calls.length
  • Replace .lastCall.args[N] with .mock.lastCall?.[N]
  • Replace .firstCall?.args[N] with .mock.calls[0]?.[N]
  • Replace .getCall(N).firstArg with .mock.calls[N][0]
  • Replace .resetHistory() with .mockClear()

Files Modified

x-charts:

  • BarChart/checkClickEvent.test.tsx
  • ChartsLocalizationProvider/ChartsLocalizationProvider.test.tsx
  • LineChart/checkClickEvent.test.tsx
  • PieChart/checkClickEvent.test.tsx
  • RadarChart/RadarChart.test.tsx, RadarChart/checkClickEvent.test.tsx
  • ScatterChart/checkClickEvent.test.tsx
  • internals/animation/useAnimate.test.tsx
  • internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxis.axisHighlight.test.tsx

x-charts-premium:

  • ChartsRenderer/ChartsRenderer.test.tsx

x-charts-pro:

  • ChartZoomSlider/ChartZoomSlider.test.tsx

  • FunnelChart/checkClickEvent.test.tsx

  • LineChartPro/LineChartPro.zoom.test.tsx

  • ScatterChartPro/ScatterChartPro.zoom.test.tsx

  • BarChartPro/BarChartPro.zoom.test.tsx

  • internals/plugins/useChartProZoom/ZoomInteractionConfig.test.tsx

  • I have followed (at least) the PR section of the contributing guide.

Original prompt

Migrate from sinon to Vitest mocking utilities for x-charts* packages.

The changes have been made in this PR, so you can just cherry-pick them: #20352


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: bernardobelchior <12778398+bernardobelchior@users.noreply.github.com>
@mui-bot
Copy link

mui-bot commented Nov 25, 2025

Deploy preview: https://deploy-preview-20444--material-ui-x.netlify.app/

Bundle size report

Bundle Parsed size Gzip size
@mui/x-data-grid 0B(0.00%) 0B(0.00%)
@mui/x-data-grid-pro 0B(0.00%) 0B(0.00%)
@mui/x-data-grid-premium 0B(0.00%) 0B(0.00%)
@mui/x-charts 0B(0.00%) 0B(0.00%)
@mui/x-charts-pro 0B(0.00%) 0B(0.00%)
@mui/x-charts-premium 0B(0.00%) 0B(0.00%)
@mui/x-date-pickers 0B(0.00%) 0B(0.00%)
@mui/x-date-pickers-pro 0B(0.00%) 0B(0.00%)
@mui/x-tree-view 0B(0.00%) 0B(0.00%)
@mui/x-tree-view-pro 0B(0.00%) 0B(0.00%)

Details of bundle changes

Generated by 🚫 dangerJS against dbb147c

Copilot AI changed the title [WIP] Migrate mocking utilities for x-charts packages [charts] Migrate from sinon to Vitest mocking utilities for x-charts* packages Nov 25, 2025
Copilot finished work on behalf of bernardobelchior November 25, 2025 13:26
@bernardobelchior
Copy link
Member

@copilot prefer array.at(-1) to array[array.length-1].

Also, run pnpm prettier

Co-authored-by: bernardobelchior <12778398+bernardobelchior@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Nov 25, 2025

@copilot prefer array.at(-1) to array[array.length-1].

Also, run pnpm prettier

Done in c953fe1. Changed all occurrences of array[array.length - 1] to array.at(-1) and ran prettier.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • iojs.org
    • Triggering command: /usr/bin/curl curl -q --fail --compressed -L -s REDACTED -o - (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot finished work on behalf of bernardobelchior November 25, 2025 13:54
@bernardobelchior
Copy link
Member

@copilot Fix types:

> @mui/x-charts@8.19.0 typescript /tmp/mui/packages/x-charts
> tsc -p tsconfig.json

src/BarChart/checkClickEvent.test.tsx(62,14): error TS2532: Object is possibly 'undefined'.
src/BarChart/checkClickEvent.test.tsx(76,14): error TS2532: Object is possibly 'undefined'.
src/BarChart/checkClickEvent.test.tsx(117,16): error TS2532: Object is possibly 'undefined'.
src/BarChart/checkClickEvent.test.tsx(131,16): error TS2532: Object is possibly 'undefined'.
src/BarChart/checkClickEvent.test.tsx(185,14): error TS2532: Object is possibly 'undefined'.
src/BarChart/checkClickEvent.test.tsx(192,14): error TS2532: Object is possibly 'undefined'.
src/BarChart/checkClickEvent.test.tsx(199,14): error TS2532: Object is possibly 'undefined'.
src/ChartsLocalizationProvider/ChartsLocalizationProvider.test.tsx(47,42): error TS2532: Object is possibly 'undefined'.
src/ChartsLocalizationProvider/ChartsLocalizationProvider.test.tsx(73,42): error TS2532: Object is possibly 'undefined'.
src/ChartsLocalizationProvider/ChartsLocalizationProvider.test.tsx(88,42): error TS2532: Object is possibly 'undefined'.
src/ChartsLocalizationProvider/ChartsLocalizationProvider.test.tsx(103,42): error TS2532: Object is possibly 'undefined'.
src/LineChart/checkClickEvent.test.tsx(56,14): error TS2532: Object is possibly 'undefined'.
src/LineChart/checkClickEvent.test.tsx(70,14): error TS2532: Object is possibly 'undefined'.
src/LineChart/checkClickEvent.test.tsx(130,14): error TS2532: Object is possibly 'undefined'.
src/LineChart/checkClickEvent.test.tsx(137,14): error TS2532: Object is possibly 'undefined'.
src/LineChart/checkClickEvent.test.tsx(144,14): error TS2532: Object is possibly 'undefined'.
src/LineChart/checkClickEvent.test.tsx(198,14): error TS2532: Object is possibly 'undefined'.
src/LineChart/checkClickEvent.test.tsx(204,14): error TS2532: Object is possibly 'undefined'.
src/LineChart/checkClickEvent.test.tsx(257,14): error TS2532: Object is possibly 'undefined'.
src/LineChart/checkClickEvent.test.tsx(263,14): error TS2532: Object is possibly 'undefined'.
src/PieChart/checkClickEvent.test.tsx(61,14): error TS2532: Object is possibly 'undefined'.
src/PieChart/checkClickEvent.test.tsx(68,14): error TS2532: Object is possibly 'undefined'.
src/RadarChart/checkClickEvent.test.tsx(47,14): error TS2532: Object is possibly 'undefined'.
src/RadarChart/checkClickEvent.test.tsx(61,14): error TS2532: Object is possibly 'undefined'.
src/RadarChart/checkClickEvent.test.tsx(97,16): error TS2532: Object is possibly 'undefined'.
src/RadarChart/checkClickEvent.test.tsx(111,16): error TS2532: Object is possibly 'undefined'.
src/RadarChart/checkClickEvent.test.tsx(154,14): error TS2532: Object is possibly 'undefined'.
src/RadarChart/checkClickEvent.test.tsx(161,14): error TS2532: Object is possibly 'undefined'.
src/RadarChart/checkClickEvent.test.tsx(168,14): error TS2532: Object is possibly 'undefined'.
src/RadarChart/checkClickEvent.test.tsx(210,14): error TS2532: Object is possibly 'undefined'.
src/RadarChart/checkClickEvent.test.tsx(223,14): error TS2532: Object is possibly 'undefined'.
src/ScatterChart/checkClickEvent.test.tsx(60,14): error TS2532: Object is possibly 'undefined'.
src/ScatterChart/checkClickEvent.test.tsx(73,14): error TS2532: Object is possibly 'undefined'.
src/ScatterChart/checkClickEvent.test.tsx(110,14): error TS2532: Object is possibly 'undefined'.
src/ScatterChart/checkClickEvent.test.tsx(179,14): error TS2532: Object is possibly 'undefined'.
src/internals/animation/useAnimate.test.tsx(130,44): error TS2345: Argument of type 'number | undefined' is not assignable to parameter of type 'number | Date'.
  Type 'undefined' is not assignable to type 'number | Date'.
src/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxis.axisHighlight.test.tsx(94,12): error TS2532: Object is possibly 'undefined'.
src/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxis.axisHighlight.test.tsx(103,12): error TS2532: Object is possibly 'undefined'.
src/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxis.axisHighlight.test.tsx(129,12): error TS2532: Object is possibly 'undefined'.
src/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxis.axisHighlight.test.tsx(161,12): error TS2532: Object is possibly 'undefined'.
src/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxis.axisHighlight.test.tsx(170,12): error TS2532: Object is possibly 'undefined'.
 ELIFECYCLE  Command failed with exit code 2.

> @mui/x-data-grid-pro:typescript


> @mui/x-data-grid-pro@8.19.0 typescript /tmp/mui/packages/x-data-grid-pro
> tsc -p tsconfig.json


> @mui/x-charts-pro:typescript


> @mui/x-charts-pro@8.19.0 typescript /tmp/mui/packages/x-charts-pro
> tsc -p tsconfig.json

src/FunnelChart/checkClickEvent.test.tsx(74,14): error TS2532: Object is possibly 'undefined'.
src/FunnelChart/checkClickEvent.test.tsx(88,14): error TS2532: Object is possibly 'undefined'.
src/FunnelChart/checkClickEvent.test.tsx(124,16): error TS2532: Object is possibly 'undefined'.
src/FunnelChart/checkClickEvent.test.tsx(138,16): error TS2532: Object is possibly 'undefined'.
src/FunnelChart/checkClickEvent.test.tsx(175,16): error TS2532: Object is possibly 'undefined'.
src/FunnelChart/checkClickEvent.test.tsx(189,16): error TS2532: Object is possibly 'undefined'.
src/FunnelChart/checkClickEvent.test.tsx(231,14): error TS2532: Object is possibly 'undefined'.
src/FunnelChart/checkClickEvent.test.tsx(238,14): error TS2532: Object is possibly 'undefined'.
src/FunnelChart/checkClickEvent.test.tsx(245,14): error TS2532: Object is possibly 'undefined'.
src/FunnelChart/checkClickEvent.test.tsx(251,14): error TS2532: Object is possibly 'undefined'.
 ELIFECYCLE  Command failed with exit code 2.

> @mui/x-charts-premium:typescript


> @mui/x-charts-premium@8.19.0 typescript /tmp/mui/packages/x-charts-premium
> tsc -p tsconfig.json

src/ChartsRenderer/ChartsRenderer.test.tsx(44,12): error TS2532: Object is possibly 'undefined'.
src/ChartsRenderer/ChartsRenderer.test.tsx(61,19): error TS2532: Object is possibly 'undefined'.
src/ChartsRenderer/ChartsRenderer.test.tsx(81,19): error TS2532: Object is possibly 'undefined'.
src/ChartsRenderer/ChartsRenderer.test.tsx(99,19): error TS2532: Object is possibly 'undefined'.
 ELIFECYCLE  Command failed with exit code 2.

Co-authored-by: bernardobelchior <12778398+bernardobelchior@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Nov 25, 2025

@copilot Fix types:

Fixed in 9c511ab. Added non-null assertions (.at(-1)!) to tell TypeScript the value is defined.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • iojs.org
    • Triggering command: /usr/bin/curl curl -q --fail --compressed -L -s REDACTED -o - (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot finished work on behalf of bernardobelchior November 25, 2025 14:13
@bernardobelchior bernardobelchior added type: enhancement It’s an improvement, but we can’t make up our mind whether it's a bug fix or a new feature. scope: charts Changes related to the charts. labels Nov 25, 2025
@codspeed-hq
Copy link

codspeed-hq bot commented Nov 25, 2025

CodSpeed Performance Report

Merging #20444 will not alter performance

Comparing copilot/migrate-sinon-to-vitest-again (dbb147c) with master (ba13a10)

Summary

✅ 13 untouched

@bernardobelchior bernardobelchior marked this pull request as ready for review November 25, 2025 15:04
Copy link
Member

@JCQuintas JCQuintas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you are planning to add this all other packages, it would be nice to have a eslint rule to prevent us from using sinon again in new tests :)

]);

expect(onItemClick.lastCall.args[1]).to.deep.equal({
expect(onItemClick.mock.calls.at(-1)![1]).to.deep.equal({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could replace all these mock.calls.at(-1) with mock.lastCall, but optional

Copy link
Member

@bernardobelchior bernardobelchior Nov 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot does mock.lastCall work here? If so, update it all over this PR

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, mock.lastCall works here. Replaced all occurrences in 7c4939c.

@bernardobelchior
Copy link
Member

If you are planning to add this all other packages, it would be nice to have a eslint rule to prevent us from using sinon again in new tests :)

Isn't removing the dependency enough? That's what I was imagining.

Co-authored-by: bernardobelchior <12778398+bernardobelchior@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Nov 27, 2025

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • iojs.org
    • Triggering command: /usr/bin/curl curl -q --fail --compressed -L -s REDACTED -o - (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot finished work on behalf of bernardobelchior November 27, 2025 07:50
@JCQuintas
Copy link
Member

If you are planning to add this all other packages, it would be nice to have a eslint rule to prevent us from using sinon again in new tests :)

Isn't removing the dependency enough? That's what I was imagining.

I don't think it will in our case, sinon is probably installed from the mui/materia package as well

);

expect(onRenderSpy.lastCall.firstArg).to.equal('line');
expect(onRenderSpy.mock.lastCall![0]).to.equal('line');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should probably be optional access instead

Suggested change
expect(onRenderSpy.mock.lastCall![0]).to.equal('line');
expect(onRenderSpy.mock.lastCall?.[0]).to.equal('line');

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot use ?. instead of ! when accessing potentially null or undefined values

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in dbb147c. Changed mock.lastCall! to mock.lastCall?. across all files.

…k.lastCall

Co-authored-by: bernardobelchior <12778398+bernardobelchior@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Nov 27, 2025

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • iojs.org
    • Triggering command: /usr/bin/curl curl -q --fail --compressed -L -s REDACTED -o - (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot finished work on behalf of bernardobelchior November 27, 2025 10:47
@JCQuintas JCQuintas enabled auto-merge (squash) November 27, 2025 10:49
@JCQuintas JCQuintas merged commit 420e924 into master Nov 27, 2025
28 checks passed
@JCQuintas JCQuintas deleted the copilot/migrate-sinon-to-vitest-again branch November 27, 2025 11:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope: charts Changes related to the charts. type: enhancement It’s an improvement, but we can’t make up our mind whether it's a bug fix or a new feature.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants