Skip to content

test(useVocal): 'creates SpeechRecognition instance' uses toBeDefined(), which passes even if ref.current stays null #252

Description

@untemps

Summary

The supported-branch test in src/hooks/__tests__/useVocal.test.ts (lines 126-133) asserts instance creation with expect(ref.current).toBeDefined(). In vitest, toBeDefined() only fails for undefinednull counts as defined — so the test passes whether or not the instance was actually created and assigned.

Current state

useVocal initializes ref = useRef<VocalInstance | null>(null) (useVocal.ts:36) and only assigns ref.current = instance inside the effect when supported (useVocal.ts:43-44). The matching no-support test correctly uses .toBeNull() (line 27) — which is exactly the value the supported test would also observe on a creation/assignment regression. No other supported-block test compensates: tests at lines 135, 405-415, and 437-453 only assert that createVocal was called (call counts/args), not that ref.current holds the returned instance. So a broken ref.current = instance assignment would go undetected.

Proposed improvement

Assert expect(ref.current).not.toBeNull() (or capture the mocked return value and assert .toBe(instance)) so the test actually verifies the instance was created and assigned.

Metadata

Metadata

Assignees

No one assigned

    Labels

    choreMaintenance, tooling, tests

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions