Skip to content

test(jsx): add useShortcuts unit tests#1708

Open
Harshithk951 wants to merge 1 commit into
Karanjot786:mainfrom
Harshithk951:test-shortcuts
Open

test(jsx): add useShortcuts unit tests#1708
Harshithk951 wants to merge 1 commit into
Karanjot786:mainfrom
Harshithk951:test-shortcuts

Conversation

@Harshithk951

@Harshithk951 Harshithk951 commented Jun 21, 2026

Copy link
Copy Markdown
Contributor

Description

This PR adds comprehensive unit tests for packages/jsx/src/hooks/useShortcuts.ts to verify its functional correctness and prevent regressions.

Changes

  • Added useShortcuts.test.ts to verify the behavior of the useShortcuts hook and registerShortcut function:
    • Registration: Verifies that registerShortcut appends a new shortcut to the list.
    • Retrieval: Verifies that useShortcuts returns the list of registered shortcuts.

Related Issue

Closes #1706

Summary by CodeRabbit

  • Tests
    • Added test coverage for the shortcuts hook to verify registration and functionality updates.

@github-actions github-actions Bot added type:testing +10 pts. Tests. area:jsx @termuijs/jsx labels Jun 21, 2026
@coderabbitai

coderabbitai Bot commented Jun 21, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

A new Vitest test file is added for the useShortcuts hook at packages/jsx/src/hooks/useShortcuts.test.ts. It contains two test cases: one verifying the hook returns an array initially, and one verifying that calling registerShortcut appends the new shortcut to the list returned by useShortcuts.

Changes

useShortcuts Hook Tests

Layer / File(s) Summary
useShortcuts test cases
packages/jsx/src/hooks/useShortcuts.test.ts
Adds two Vitest test cases: asserts the hook returns an array on initial call, and asserts that registerShortcut causes useShortcuts to return an updated list with the newly registered shortcut appended as the last entry.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Suggested labels

type:testing, area:jsx

Suggested reviewers

  • Karanjot786

Poem

🐇 Hippity hop, a test appears,
Shortcuts now checked without any fears!
registerShortcut appends with glee,
Arrays returned for all to see.
The bunny approves — tests running free! 🎉

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding unit tests for the useShortcuts hook in the jsx package.
Description check ✅ Passed The description provides clear explanation of changes, links the related issue (#1706), identifies the affected package, and follows the PR structure well.
Linked Issues check ✅ Passed The PR fulfills all requirements from issue #1706: creates useShortcuts.test.ts file, verifies registerShortcut appends shortcuts, and verifies useShortcuts returns the list.
Out of Scope Changes check ✅ Passed All changes are within scope—only the new test file was added to verify useShortcuts hook functionality as specified in issue #1706.
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.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

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

📥 Commits

Reviewing files that changed from the base of the PR and between 35c2213 and ba793ca.

📒 Files selected for processing (1)
  • packages/jsx/src/hooks/useShortcuts.test.ts

Comment thread packages/jsx/src/hooks/useShortcuts.test.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:jsx @termuijs/jsx type:testing +10 pts. Tests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] Unit Tests for useShortcuts in packages/jsx/src/hooks/useShortcuts.ts

1 participant