UNPKG

analytica-frontend-lib

Version:

Repositório público dos componentes utilizados nas plataformas da Analytica Ensino

42 lines 1.25 kB
/** * Helper to mock window.location in jsdom environments where * Object.defineProperty(window, 'location', ...) no longer works. * * jsdom marks window.location as [Unforgeable] (non-configurable), * but we can override properties via the internal impl symbol. */ type LocationProps = { hostname?: string; protocol?: string; port?: string; href?: string; search?: string; origin?: string; pathname?: string; hash?: string; replace?: (url: string) => void; assign?: (url: string) => void; reload?: () => void; }; type MockLocationResult = { restore: () => void; getMockLocation: () => LocationProps; }; /** * Mock window.location properties in jsdom. * * Usage: * const { restore } = mockWindowLocation({ hostname: 'example.com', protocol: 'https:', port: '' }); * // ... test code ... * restore(); * * For href setter capture: * const mockLoc = { href: '' }; * const { restore } = mockWindowLocation(mockLoc); * // code sets window.location.href = 'http://...' * expect(mockLoc.href).toBe('http://...'); * restore(); */ export declare function mockWindowLocation(props: LocationProps): MockLocationResult; export {}; //# sourceMappingURL=mockLocation.d.ts.map