forked from FlowwStar/FlowStar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuse-show-usd.test.ts
More file actions
29 lines (25 loc) · 916 Bytes
/
Copy pathuse-show-usd.test.ts
File metadata and controls
29 lines (25 loc) · 916 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { describe, it, expect, beforeEach } from 'vitest'
import { renderHook, act } from '@testing-library/react'
import { useShowUsd } from '@/hooks/use-show-usd'
describe('useShowUsd', () => {
beforeEach(() => {
localStorage.clear()
})
it('defaults to showing USD when nothing is stored', () => {
const { result } = renderHook(() => useShowUsd())
expect(result.current[0]).toBe(true)
})
it('reads a previously stored false value', () => {
localStorage.setItem('flowstar-show-usd', 'false')
const { result } = renderHook(() => useShowUsd())
expect(result.current[0]).toBe(false)
})
it('toggle updates state and persists to localStorage', () => {
const { result } = renderHook(() => useShowUsd())
act(() => {
result.current[1](false)
})
expect(result.current[0]).toBe(false)
expect(localStorage.getItem('flowstar-show-usd')).toBe('false')
})
})