Skip to content

Instantly share code, notes, and snippets.

View dwat3r's full-sized avatar
💻
Working from my computer

Oliver Hechtl dwat3r

💻
Working from my computer
  • Dé VakantieDiscounter
  • Budapest
View GitHub Profile
@dwat3r
dwat3r / locationMock.ts
Created October 9, 2024 13:37
mock window.location
// copied source code from https://github.com/OxfordAbstracts/vitest-location-mock
// and fixed relative url handling on href assignment
export const replaceLocation = (): void => {
// Do nothing if window is not defined
// - Prevents an error when importing this mock in the setup file when some tests use the node test environment instead of JSDOM
if (typeof window === 'undefined') {
return
}
// Set the base URL for relative URLs to `HOST` environment variable, defaults to localhost
const locationMock = new LocationMock('http://localhost/')