React - Testing custom hooks
React testing library provides a way to test a custom hook by using renderHook
from @testing-library/react
.
1
2
3
4
5
6
7
8
9
import { expect, test } from "@jest/globals"
import { renderHook } from "@testing-library/react"
import { useImageDropZone } from "../hooks/useImageDropZone"
test("should render useImageDropZone", async () => {
const { result } = renderHook(() => useImageDropZone())
const [filename, fileContent, ImageDropZone] = result.current
expect(ImageDropZone).toBeDefined()
})