@testing-library/react-hooks
Version:
Simple and complete React hooks testing utilities that encourage good testing practices.
22 lines (15 loc) • 617 B
text/typescript
import { useReducer } from 'react'
describe('useReducer tests', () => {
runForRenderers(['default', 'dom', 'native', 'server/hydrated'], ({ renderHook, act }) => {
test('should handle useReducer hook', () => {
const reducer = (state: number, action: { type: string }) =>
action.type === 'inc' ? state + 1 : state
const { result } = renderHook(() => useReducer(reducer, 0))
const [initialState, dispatch] = result.current
expect(initialState).toBe(0)
act(() => dispatch({ type: 'inc' }))
const [state] = result.current
expect(state).toBe(1)
})
})
})