-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuseToast.test.tsx
More file actions
31 lines (27 loc) · 988 Bytes
/
Copy pathuseToast.test.tsx
File metadata and controls
31 lines (27 loc) · 988 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
30
31
import { describe, expect, it } from 'vitest'
import { renderHook, act } from '@testing-library/react'
import type { ReactNode } from 'react'
import { ToastProvider } from '@/context/ToastContext'
import { useToast } from './useToast'
const wrapper = ({ children }: { children: ReactNode }) => (
<ToastProvider>{children}</ToastProvider>
)
describe('useToast', () => {
it('throws when used outside ToastProvider', () => {
expect(() => renderHook(() => useToast())).toThrowError(
/useToast must be used within a ToastProvider/
)
})
it('returns showToast function inside provider', () => {
const { result } = renderHook(() => useToast(), { wrapper })
expect(typeof result.current.showToast).toBe('function')
})
it('showToast does not throw when called', () => {
const { result } = renderHook(() => useToast(), { wrapper })
expect(() => {
act(() => {
result.current.showToast('hi', 'success')
})
}).not.toThrow()
})
})