-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[code-infra] Update some date-pickers tests for vitest #17083
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Thanks for adding a type label to the PR! 👍 |
Deploy preview: https://deploy-preview-17083--material-ui-x.netlify.app/ |
it('should not use the mobile picker by default', () => { | ||
// Test with accessible DOM structure | ||
window.matchMedia = stubMatchMedia(true); |
There was a problem hiding this comment.
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.
if (!inClock && clockConfig) { | ||
let timer: sinon.SinonFakeTimers | null = null; | ||
beforeEach(() => { | ||
timer = sinon.useFakeTimers({ now: clockConfig, toFake: ['Date'] }); |
There was a problem hiding this comment.
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? 🤔
These are improvements made during the
vitest
PRI'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.