Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for '@reach/utils' and compatibility check with react 18 #960

Open
wants to merge 15 commits into
base: dev
Choose a base branch
from
Open
Prev Previous commit
Next Next commit
add tests for useUpdateEffect
dartess committed Aug 25, 2022
commit 8931cd7935dbe94ee3c75a706949c8b6573f0467
29 changes: 29 additions & 0 deletions packages/utils/__tests__/use-update-effect.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { useState } from "react";
import { afterEach, describe, expect, it, vi } from "vitest";
import { renderHook, cleanupHooks, actHooks } from "@reach-internal/test/utils";
import { useUpdateEffect } from "@reach/utils";

afterEach(cleanupHooks);

describe("useUpdateEffect", () => {
it("should do not call effect on mount", () => {
const effect = vi.fn();
renderHook(() => useUpdateEffect(effect, []));

expect(effect).not.toHaveBeenCalled();
});

it("should call effect on every update", () => {
const effect = vi.fn();
const { result } = renderHook(() => {
const [dependency, setDependency] = useState(0);
useUpdateEffect(effect, [dependency]);
return { setDependency };
});

actHooks(() => result.current.setDependency(10));
expect(effect).toHaveBeenCalledTimes(1);
actHooks(() => result.current.setDependency(22));
expect(effect).toHaveBeenCalledTimes(2);
});
});