test(jsx): add useShortcuts unit tests#1708
Conversation
📝 WalkthroughWalkthroughA new Vitest test file is added for the ChangesuseShortcuts Hook Tests
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/jsx/src/hooks/useShortcuts.test.ts`:
- Around line 4-24: The tests share module-scoped state that persists across
test runs, causing order-dependent failures. Add a beforeEach hook to reset or
reimport the module state before each test to ensure isolation. In the first
test (returns empty array initially), replace the Array.isArray check with an
assertion that validates the actual initial contents (likely an empty array)
rather than just the type. In the second test (registers new shortcut), ensure
the initial length is captured fresh after any state reset so the length
comparison is accurate. Consider implementing a reset helper function that
clears registered shortcuts or re-imports useShortcuts and registerShortcut
fresh for each test.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 3e21259b-c6b9-4489-9dc6-3fab68d53677
📒 Files selected for processing (1)
packages/jsx/src/hooks/useShortcuts.test.ts
Description
This PR adds comprehensive unit tests for
packages/jsx/src/hooks/useShortcuts.tsto verify its functional correctness and prevent regressions.Changes
useShortcutshook andregisterShortcutfunction:registerShortcutappends a new shortcut to the list.useShortcutsreturns the list of registered shortcuts.Related Issue
Closes #1706
Summary by CodeRabbit