Fix test to work with new jsdom restriction

since jsdom 21, it's no longer possible to mock window.location
See : https://github.com/jsdom/jsdom/issues/3492
This commit is contained in:
Gaetan Craig-Riou
2025-11-11 14:37:36 +11:00
parent 2729fb14d6
commit 4e62e20fa8
5 changed files with 21 additions and 41 deletions

View File

@@ -3,7 +3,7 @@
*/
import { Application } from "stimulus";
import tabs_and_panels_controller from "../../../app/webpacker/controllers/tabs_and_panels_controller";
import tabs_and_panels_controller from "controllers/tabs_and_panels_controller";
describe("TabsAndPanelsController", () => {
beforeAll(() => {
@@ -90,16 +90,8 @@ describe("TabsAndPanelsController", () => {
});
describe("when valid anchor is specified in the url", () => {
const oldWindowLocation = window.location;
beforeAll(() => {
Object.defineProperty(window, "location", {
value: new URL("http://example.com/#boo_panel"),
configurable: true,
});
});
afterAll(() => {
delete window.location;
window.location = oldWindowLocation;
history.pushState({}, "", "#boo_panel");
});
it("#activateFromWindowLocationOrDefaultPanelTarget show panel based on anchor", () => {
@@ -121,16 +113,8 @@ describe("TabsAndPanelsController", () => {
});
describe("when non valid anchor is specified in the url", () => {
const oldWindowLocation = window.location;
beforeAll(() => {
Object.defineProperty(window, "location", {
value: new URL("http://example.com/#non_valid_panel"),
configurable: true,
});
});
afterAll(() => {
delete window.location;
window.location = oldWindowLocation;
history.pushState({}, "", "#non_valid_panel");
});
it("#activateFromWindowLocationOrDefaultPanelTarget show default panel", () => {