1import { renderHook, act } from '@testing-library/react-hooks'
2import useCounter from './useCounter'
3
4test('should increment counter', () => {
5 const { result } = renderHook(() => useCounter())
6
7 act(() => {
8 result.current.increment()
9 })
10
11 expect(result.current.count).toBe(1)
12})
1import { useState, useCallback } from 'react'
2
3function useCounter() {
4 const [count, setCount] = useState(0)
5
6 const increment = useCallback(() => setCount((x) => x + 1), [])
7
8 return { count, increment }
9}
10
11export default useCounter