-
Notifications
You must be signed in to change notification settings - Fork 616
refactor: update hooks tests from Jest to Vitest #6150
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
|
👋 Hi, this pull request contains changes to the source code that github/github depends on. If you are GitHub staff, we recommend testing these changes with github/github using the integration workflow. Thanks! |
size-limit report 📦
|
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.
Pull Request Overview
This PR migrates our hook tests from Jest to Vitest, updating configuration, test patterns, and API usages to the Vitest ecosystem.
- Added
src/hooks
test glob tovitest.config.mts
and adjusted Jest config to include hooks in coverage. - Replaced Jest APIs (
jest.fn
,jest.spyOn
) with Vitest equivalents (vi.fn
,vi.spyOn
) and importedit/test
andexpect
from Vitest. - Updated responsive hook tests to use Vitest’s browser context (
page.viewport
) and refactored hook tests to render components instead of usingrenderHook
.
Reviewed Changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
packages/react/vitest.config.mts | Added src/hooks/**/*.test.* pattern and reordered test globs. |
packages/react/src/hooks/tests/useSyncedState.test.tsx | Added Vitest imports for test and expect . |
packages/react/src/hooks/tests/useSlots.test.tsx | Switched from renderHook to rendering a test component and using Vitest. |
packages/react/src/hooks/tests/useResponsiveValue.test.tsx | Migrated to Vitest’s it /expect imports and page.viewport usage. |
packages/react/src/hooks/tests/useProvidedStateOrCreate.test.tsx | Trimmed rendered text and added Vitest imports. |
packages/react/src/hooks/tests/useOpenAndCloseFocus.test.tsx | Added Vitest imports and replaced imports accordingly. |
packages/react/src/hooks/tests/useOnOutsideClick.test.tsx | Replaced jest.fn with vi.fn and imported Vitest APIs. |
packages/react/src/hooks/tests/useOnEscapePress.test.tsx | Replaced jest.fn with vi.fn and imported Vitest APIs. |
packages/react/src/hooks/tests/useMnemonics.test.tsx | Switched from Jest timers/mocks to Vitest (vi.useFakeTimers ). |
packages/react/src/hooks/tests/useMenuInitialFocus.test.tsx | Updated imports to Vitest and adjusted relative hook import path. |
packages/react/src/hooks/tests/useMedia.test.tsx | Replaced Jest mocks with vi.fn and updated Vitest imports. |
packages/react/src/hooks/tests/useControllableState.test.tsx | Migrated spies to vi.spyOn and consolidated Vitest imports. |
packages/react/src/hooks/tests/useAnchoredPosition.test.tsx | Added Vitest imports and replaced jest.fn with vi.fn . |
packages/react/jest.config.js | Added src/hooks/ to Jest coverage patterns. |
Comments suppressed due to low confidence (1)
packages/react/src/hooks/tests/useResponsiveValue.test.tsx:2
- This file uses
render
andact
but neither is imported. Please addimport {render, act} from '@testing-library/react'
at the top to avoid runtime errors.
import {expect, it} from 'vitest'
@@ -1,4 +1,5 @@ | |||
import {act, renderHook} from '@testing-library/react' | |||
import {test, expect} from 'vitest' |
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.
[nitpick] Some test files use test
, others use it
. Consider standardizing on one keyword for consistency across the codebase.
import {test, expect} from 'vitest' | |
import {it, expect} from 'vitest' |
Copilot uses AI. Check for mistakes.
…ests-to-vitest-may-30
Update our tests for hooks from Jest to Vitest