React hooks testing utils for Enzyme
Easily test react hooks with Enzyme, using enzyme implementation of the renderHook testing util. Based upon React Hooks Testing Library. Inspired by the teachings of Kent C. Dodds in his Epic React Workshop.
npm install --save-dev enzyme-react-hooks
import { act } from "react-dom/test-utils";
import { renderHook } from "enzyme-react-hooks";
import { useCounter } from "./useCounter";
it("should increment counter", () => {
const { result } = renderHook(useCounter);
act(() => result.current.increment());
expect(result.current.count).toBe(1);
});
Kent C. Dodds' Epic React Workshop
MIT © Igor Pavloski