react hook testing library code example
Example 1: testing library react hooks
import { renderHook, act } from '@testing-library/react-hooks'
import useCounter from './useCounter'
test('should increment counter', () => {
const { result } = renderHook(() => useCounter())
act(() => {
result.current.increment()
})
expect(result.current.count).toBe(1)
})
Example 2: react testing library for hooks
npm install --save-dev @testing-library/react-hooks