react-hooks/tests/useTitle.test.ts

24 lines
660 B
TypeScript

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);
});
});