UNPKG

@testing-library/react-hooks

Version:

Simple and complete React hooks testing utilities that encourage good testing practices.

24 lines (19 loc) 718 B
import { useRef, useImperativeHandle } from 'react' describe('useHook tests', () => { runForRenderers(['default', 'dom', 'native', 'server/hydrated'], ({ renderHook }) => { test('should handle useRef hook', () => { const { result } = renderHook(() => useRef('value')) expect(result.current.current).toBe('value') }) test('should handle useImperativeHandle hook', () => { const { result } = renderHook(() => { const ref = useRef<Record<string, () => boolean>>({}) useImperativeHandle(ref, () => ({ fakeImperativeMethod: () => true })) return ref }) expect(result.current.current.fakeImperativeMethod()).toBe(true) }) }) })