Skip to content

Instantly share code, notes, and snippets.

View Tofandel's full-sized avatar

Adrien Foulon Tofandel

View GitHub Profile
@tkrotoff
tkrotoff / #mockWindowLocation.ts
Last active March 14, 2024 16:39
Jest/Vitest mocks for JSDOM window.location & window.history
/* eslint-disable unicorn/no-null */
/*
* Resetting window.location between tests is unfortunately a hard topic with JSDOM.
*
* https://gist.github.com/tkrotoff/52f4a29e919445d6e97f9a9e44ada449
*
* FIXME JSDOM leaves the history in place after every test, so the history will be dirty.
* Also its implementations for window.location and window.history are lacking.
* - https://github.com/jsdom/jsdom/blob/22.1.0/lib/jsdom/living/window/Location-impl.js