-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
/
Copy pathuseReduxContext.spec.tsx
40 lines (33 loc) · 1.27 KB
/
useReduxContext.spec.tsx
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
32
33
34
35
36
37
38
39
40
import { renderHook } from '@testing-library/react-hooks'
import { createContext } from 'react'
import type { ReactReduxContextValue } from '../../src/components/Context'
import {
createReduxContextHook,
useReduxContext,
} from '../../src/hooks/useReduxContext'
describe('React', () => {
describe('hooks', () => {
describe('useReduxContext', () => {
it('throws if component is not wrapped in provider', () => {
const spy = jest.spyOn(console, 'error').mockImplementation(() => {})
const { result } = renderHook(() => useReduxContext())
expect(result.error.message).toMatch(
/could not find react-redux context value/
)
spy.mockRestore()
})
})
describe('createReduxContextHook', () => {
it('throws if component is not wrapped in provider', () => {
const customContext = createContext<ReactReduxContextValue | null>(null)
const useCustomReduxContext = createReduxContextHook(customContext)
const spy = jest.spyOn(console, 'error').mockImplementation(() => {})
const { result } = renderHook(() => useCustomReduxContext())
expect(result.error.message).toMatch(
/could not find react-redux context value/
)
spy.mockRestore()
})
})
})
})