react-hooks/tests/useTitle.test.ts

24 lines
660 B
TypeScript
Raw Permalink Normal View History

2023-10-31 03:20:24 +02:00
import { renderHook, act } from "@testing-library/react-hooks";
import { useTitle } from "../src";
describe("useTitle", () => {
it("should set the document title", () => {
const title = "New Page Title";
renderHook(() => useTitle(title));
expect(document.title).toBe(title);
});
it("should reset the document title when unmounted", () => {
const title = "New Page Title";
const { unmount } = renderHook(() => useTitle(title));
expect(document.title).toBe(title);
act(() => {
unmount();
});
// The document title should now be reset to its previous value
expect(document.title).not.toBe(title);
});
});