Dùng @testing-library/react với renderHook utility: const { result } = renderHook(() => useMyHook()); expect(result.current.value).toBe(expected).
- Để test interactions:
act(() => { result.current.setValue('new') }). - Với async hooks dùng
waitFor.renderHooktạo component test wrapper để hooks có React context đầy đủ.
Use @testing-library/react with the renderHook utility: const { result } = renderHook(() => useMyHook()); expect(result.current.value).toBe(expected).
- To test interactions:
act(() => { result.current.setValue('new') }). - For async hooks use
waitFor.renderHookcreates a test component wrapper so hooks have full React context.