From ba793ca265207d2decfae2c96d310de3deb74578 Mon Sep 17 00:00:00 2001 From: Harshithk951 <186480203+Harshithk951@users.noreply.github.com> Date: Sun, 21 Jun 2026 12:15:51 +0530 Subject: [PATCH] test(jsx): add useShortcuts unit tests --- packages/jsx/src/hooks/useShortcuts.test.ts | 25 +++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 packages/jsx/src/hooks/useShortcuts.test.ts diff --git a/packages/jsx/src/hooks/useShortcuts.test.ts b/packages/jsx/src/hooks/useShortcuts.test.ts new file mode 100644 index 00000000..113c8429 --- /dev/null +++ b/packages/jsx/src/hooks/useShortcuts.test.ts @@ -0,0 +1,25 @@ +import { describe, it, expect } from 'vitest'; +import { registerShortcut, useShortcuts } from './useShortcuts.js'; + +describe('useShortcuts hook', () => { + it('returns empty array initially or already registered shortcuts', () => { + const initial = useShortcuts(); + expect(Array.isArray(initial)).toBe(true); + }); + + it('registers new shortcut and returns updated list', () => { + const initialLength = useShortcuts().length; + + const newShortcut = { + key: 'ctrl+k', + description: 'Clear console', + category: 'general', + }; + + registerShortcut(newShortcut); + + const updated = useShortcuts(); + expect(updated).toHaveLength(initialLength + 1); + expect(updated[updated.length - 1]).toEqual(newShortcut); + }); +});