test: fix act() warnings in useVaultSwitcher — settle async effect (option D)

The 'starts with default vaults' test was synchronous but the hook fires
an async useEffect on mount, causing React act() warnings when the state
update resolved after unmount. Now awaits the loaded state to let the
effect settle before the test completes.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
lucaronin
2026-03-25 23:34:52 +01:00
parent 5ec508bc38
commit 98debe15f1

View File

@@ -47,10 +47,11 @@ describe('useVaultSwitcher', () => {
})
})
it('starts with default vaults', () => {
it('starts with default vaults', async () => {
const { result } = renderHook(() => useVaultSwitcher({ onSwitch, onToast }))
expect(result.current.allVaults).toEqual(DEFAULT_VAULTS)
expect(result.current.vaultPath).toBe(DEFAULT_VAULTS[0].path)
await waitFor(() => { expect(result.current.loaded).toBe(true) })
})
it('loads persisted vaults on mount', async () => {