Skip to content

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

Merged
merged 3 commits into from
Jun 2, 2025

Conversation

joshblack
Copy link
Member

@joshblack joshblack commented May 30, 2025

Update our tests for hooks from Jest to Vitest

Copy link

changeset-bot bot commented May 30, 2025

⚠️ No Changeset found

Latest commit: a329801

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

👋 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!

@github-actions github-actions bot added the integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm label May 30, 2025
@joshblack joshblack added the skip changeset This change does not need a changelog label May 30, 2025
@joshblack joshblack marked this pull request as ready for review May 30, 2025 19:54
@Copilot Copilot AI review requested due to automatic review settings May 30, 2025 19:54
@joshblack joshblack requested a review from a team as a code owner May 30, 2025 19:54
@joshblack joshblack requested a review from hectahertz May 30, 2025 19:54
Copy link
Contributor

github-actions bot commented May 30, 2025

size-limit report 📦

Path Size
packages/react/dist/browser.esm.js 94.51 KB (0%)
packages/react/dist/browser.umd.js 94.64 KB (0%)

Copy link
Contributor

@Copilot Copilot AI left a 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 to vitest.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 imported it/test and expect from Vitest.
  • Updated responsive hook tests to use Vitest’s browser context (page.viewport) and refactored hook tests to render components instead of using renderHook.

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 and act but neither is imported. Please add import {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'
Copy link
Preview

Copilot AI May 30, 2025

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.

Suggested change
import {test, expect} from 'vitest'
import {it, expect} from 'vitest'

Copilot uses AI. Check for mistakes.

@joshblack joshblack enabled auto-merge June 2, 2025 17:25
@joshblack joshblack added this pull request to the merge queue Jun 2, 2025
Merged via the queue into main with commit 3d4dcf7 Jun 2, 2025
35 checks passed
@joshblack joshblack deleted the refactor/update-tests-to-vitest-may-30 branch June 2, 2025 17:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm skip changeset This change does not need a changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants