[Feature]: `jest.mockWindowLocation`
🚀 Feature Proposal
The jest 30 release notes acknowledge that jsdom no longer supports reassigning window.location. There are some jest issues closed as a jsdom issue, and jsdom's issue is closed as not planned. https://github.com/jestjs/jest/issues/15674 https://github.com/jestjs/jest/issues/5124 https://github.com/jsdom/jsdom/issues/3492
The release notes say @jest/environment-jsdom-abstract should help, but doesn't make it clear how. They also say jest may look for an alternative that is better suited for testing.
Scouring the linked issues I found some workarounds that involve getting a reference to the jsdom instance and calling reconfigure. This seems like a pretty good solution. Could jest expose that in the official jsdom environment or as a jest function?
Motivation
The activity on the issues makes this seem like a common use case. There's a lot of flack on the jsdom issue to support reconfiguring the window.loction, but it seems jsdom has a method, it just isn't exposed by jest.
Adding a mock function that calls jsdom.reconfigure seems like good UX and less effort than replacing jsdom, or asking packages to patch their installed jsdom.
Example
No response
Pitch
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.
Please don't auto-close this issue.
I'd be happy to work on a PR if there was any indication that jest would merge it.
+1 maybe we could at least update the release note to clarify how @jest/environment-jsdom-abstract is intended to help?
I use @jest/environment-jsdom-abstract to implement inject a mocked location object into JSDOM.
While it works without jest, it doesn't work in jest.
Maybe you'll find this helpful:
https://stackoverflow.com/questions/79784243/mock-jsdom-location-using-jest-environment-jsdom-abstract
@everett1992 my PRs got merged steadily over the time, weekly-wise. So I say, go for it :D
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.
Hey folks! Any traction on this - is there a plan to implement or accept this feature?