Skip to content

Conversation

JCQuintas
Copy link
Member

@JCQuintas JCQuintas commented Mar 22, 2025

These are improvements made during the vitest PR

I'm moving the changes out so that PR is leaner. The changes mostly revolve around removing clock='fake' usage.

Hopefully these are reasonable enough changes to be merged without issues.

Copy link

Thanks for adding a type label to the PR! 👍

@mui-bot
Copy link

mui-bot commented Mar 22, 2025

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

Generated by 🚫 dangerJS against 2a04d78

@JCQuintas JCQuintas changed the title changes [code-infra] Update some date-pickers tests for vitest Mar 23, 2025
@JCQuintas JCQuintas requested a review from a team March 23, 2025 00:20
@JCQuintas JCQuintas marked this pull request as ready for review March 23, 2025 00:20
@JCQuintas JCQuintas requested a review from a team March 23, 2025 00:20
it('should not use the mobile picker by default', () => {
// Test with accessible DOM structure
window.matchMedia = stubMatchMedia(true);
Copy link
Member

@Janpot Janpot Mar 24, 2025

Choose a reason for hiding this comment

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

edit: nvm, we're still in mocha land, to keep in mind for when we switch to vitest

Suggestion: Create a stubMatchMedia helper that cleans up after itself automatically

import { onTestFinished } from 'vitest'

function stubMatchMedia(matches) {
  const original = window.matchMedia
  window.matchMedia = ...
  onTestFinished(() => {
    window.matchMedia = original
  })
}

The hook is called in reverse order, so it should be safe to call stubMatchMedia multiple times.

@JCQuintas JCQuintas enabled auto-merge (squash) March 24, 2025 10:30
@JCQuintas JCQuintas merged commit 128c20f into mui:master Mar 24, 2025
19 of 20 checks passed
@JCQuintas JCQuintas deleted the reasonable-date-pickers branch March 24, 2025 10:40
if (!inClock && clockConfig) {
let timer: sinon.SinonFakeTimers | null = null;
beforeEach(() => {
timer = sinon.useFakeTimers({ now: clockConfig, toFake: ['Date'] });
Copy link
Member

Choose a reason for hiding this comment

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

Have you tried using the additional option added in mui/material-ui#43729? 🤔

@oliviertassinari oliviertassinari 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. and removed maintenance labels May 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
test 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.

6 participants