Skip to content

Comments

fix(repo): Mock @formkit/auto-animate/react in vitest setup#7903

Merged
jacekradko merged 3 commits intomainfrom
jacek/fix-auto-animate-test-mock
Feb 23, 2026
Merged

fix(repo): Mock @formkit/auto-animate/react in vitest setup#7903
jacekradko merged 3 commits intomainfrom
jacek/fix-auto-animate-test-mock

Conversation

@jacekradko
Copy link
Member

@jacekradko jacekradko commented Feb 23, 2026

Summary

  • Add explicit vi.mock('@formkit/auto-animate/react') to the vitest setup file to prevent unhandled requestAnimationFrame is not defined errors that fail CI

The __mocks__ directory at packages/ui/src/elements/__mocks__/@formkit/auto-animate/react/ was not being detected by Vitest for node_module mocks, so auto-animate actually ran in tests, created real timers, and leaked setTimeout callbacks that fired after jsdom teardown — causing ReferenceError: requestAnimationFrame is not defined.

Test plan

  • pnpm test --filter=@clerk/ui passes with no unhandled errors
  • Only 1 file changed: packages/clerk-js/vitest.setup.mts

Summary by CodeRabbit

  • Tests
    • Added an explicit mock for the auto-animate integration in test setup and removed a duplicate mock to consolidate behavior — improves stability and prevents timer leakage during teardown.
  • Chores
    • Added a changeset entry to track this update.

The __mocks__ directory in src/elements/ was not detected by Vitest for
node_module mocks, so auto-animate ran in tests and leaked timers that
fired after jsdom teardown, causing requestAnimationFrame errors.
@vercel
Copy link

vercel bot commented Feb 23, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
clerk-js-sandbox Ready Ready Preview, Comment Feb 23, 2026 4:25am

Request Review

@changeset-bot
Copy link

changeset-bot bot commented Feb 23, 2026

🦋 Changeset detected

Latest commit: 3cda8c6

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 0 packages

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

Not sure what this means? Click here to learn what changesets are.

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

@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 23, 2026

Open in StackBlitz

@clerk/agent-toolkit

npm i https://pkg.pr.new/@clerk/agent-toolkit@7903

@clerk/astro

npm i https://pkg.pr.new/@clerk/astro@7903

@clerk/backend

npm i https://pkg.pr.new/@clerk/backend@7903

@clerk/chrome-extension

npm i https://pkg.pr.new/@clerk/chrome-extension@7903

@clerk/clerk-js

npm i https://pkg.pr.new/@clerk/clerk-js@7903

@clerk/dev-cli

npm i https://pkg.pr.new/@clerk/dev-cli@7903

@clerk/expo

npm i https://pkg.pr.new/@clerk/expo@7903

@clerk/expo-passkeys

npm i https://pkg.pr.new/@clerk/expo-passkeys@7903

@clerk/express

npm i https://pkg.pr.new/@clerk/express@7903

@clerk/fastify

npm i https://pkg.pr.new/@clerk/fastify@7903

@clerk/hono

npm i https://pkg.pr.new/@clerk/hono@7903

@clerk/localizations

npm i https://pkg.pr.new/@clerk/localizations@7903

@clerk/nextjs

npm i https://pkg.pr.new/@clerk/nextjs@7903

@clerk/nuxt

npm i https://pkg.pr.new/@clerk/nuxt@7903

@clerk/react

npm i https://pkg.pr.new/@clerk/react@7903

@clerk/react-router

npm i https://pkg.pr.new/@clerk/react-router@7903

@clerk/shared

npm i https://pkg.pr.new/@clerk/shared@7903

@clerk/tanstack-react-start

npm i https://pkg.pr.new/@clerk/tanstack-react-start@7903

@clerk/testing

npm i https://pkg.pr.new/@clerk/testing@7903

@clerk/ui

npm i https://pkg.pr.new/@clerk/ui@7903

@clerk/upgrade

npm i https://pkg.pr.new/@clerk/upgrade@7903

@clerk/vue

npm i https://pkg.pr.new/@clerk/vue@7903

commit: 3cda8c6

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 23, 2026

No actionable comments were generated in the recent review. 🎉


📝 Walkthrough

Walkthrough

An explicit Vitest mock for @formkit/auto-animate/react was added to the test setup, providing useAutoAnimate that returns [null]. The existing mocked export for useAutoAnimate was removed from the packages/ui __mocks__ path. A new changeset file with two lines was added.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title clearly and concisely summarizes the main change: adding a mock for @formkit/auto-animate/react in the vitest setup file to fix test failures.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/clerk-js/vitest.setup.mts`:
- Around line 265-270: Tests are missing to verify the explicit vi.mock of
'@formkit/auto-animate/react' (the vi.mock call that returns useAutoAnimate: ()
=> [null]) prevents requestAnimationFrame/timer leaks; add a unit test that
imports a component relying on useAutoAnimate (or directly imports the mocked
module), mounts/render it under Vitest, asserts no pending timers or raf
callbacks after unmount/teardown (or uses vi.useFakeTimers/vi.runAllTimers to
prove no leaked timers), and include the test file in the existing test suite so
coverage records the mock behavior; reference the mocked symbol useAutoAnimate
and the vi.mock declaration in vitest.setup.mts when locating where to base the
test.

@jacekradko jacekradko changed the title fix(test): Mock @formkit/auto-animate/react in vitest setup fix(repo): Mock @formkit/auto-animate/react in vitest setup Feb 23, 2026
This mock was never picked up by Vitest since __mocks__ directories
nested inside src/ are not detected for node_module mocks. The
explicit vi.mock in vitest.setup.mts now handles this.
@jacekradko jacekradko merged commit 00de275 into main Feb 23, 2026
41 checks passed
@jacekradko jacekradko deleted the jacek/fix-auto-animate-test-mock branch February 23, 2026 04:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants