UNPKG

@frak-labs/react-sdk

Version:

React SDK of the Frak wallet, low level library to interact directly with the frak ecosystem.

55 lines (40 loc) 1.63 kB
/** * Tests for useWindowLocation hook * Tests hook that tracks window.location changes */ import { renderHook } from "@testing-library/react"; import { describe, expect, test, vi } from "vitest"; import { useWindowLocation } from "./useWindowLocation"; describe("useWindowLocation", () => { test("should return current window location", () => { const { result } = renderHook(() => useWindowLocation()); expect(result.current.location).toBeDefined(); expect(result.current.href).toBeDefined(); expect(typeof result.current.href).toBe("string"); }); test("should derive href from location", () => { const { result } = renderHook(() => useWindowLocation()); if (result.current.location) { expect(result.current.href).toBe(result.current.location.href); } }); test("should register popstate listener", () => { const addEventListenerSpy = vi.spyOn(window, "addEventListener"); renderHook(() => useWindowLocation()); expect(addEventListenerSpy).toHaveBeenCalledWith( "popstate", expect.any(Function) ); addEventListenerSpy.mockRestore(); }); test("should cleanup popstate listener on unmount", () => { const removeEventListenerSpy = vi.spyOn(window, "removeEventListener"); const { unmount } = renderHook(() => useWindowLocation()); unmount(); expect(removeEventListenerSpy).toHaveBeenCalledWith( "popstate", expect.any(Function) ); removeEventListenerSpy.mockRestore(); }); });