lumrop/tests/useTitle.test.ts

26 lines
691 B
TypeScript

// Copyright (c) 2022 Tudor Stanciu
import { renderHook, act } from "@testing-library/react";
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);
});
});