Nâng CaoReact iconReact

Làm thế nào để test custom hooks?

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. renderHook tạo component test wrapper để hooks có React context đầy đủ.

Xem toàn bộ React cùng filter theo level & chủ đề con.

Mở danh sách React