-
-
Save cpojer/e66f9a082021a82230f2595a6027f161 to your computer and use it in GitHub Desktop.
| diff --git a/lib/jsdom/browser/Window.js b/lib/jsdom/browser/Window.js | |
| index 52d011cae61c3688ec64baa5cec411d55edbda9d..298d7ec8d2cc1ea5e974262b978e6041389900f7 100644 | |
| --- a/lib/jsdom/browser/Window.js | |
| +++ b/lib/jsdom/browser/Window.js | |
| @@ -507,8 +507,8 @@ function installOwnProperties(window, options) { | |
| // [LegacyUnforgeable]: | |
| window: { configurable: false }, | |
| document: { configurable: false }, | |
| - location: { configurable: false }, | |
| - top: { configurable: false } | |
| + location: { configurable: true }, | |
| + top: { configurable: false }, | |
| }); |
Using patch-package to apply this. 👍
for jsdom 26.1.0 it shifted one line (i guess it will happen in between versions a lot)
diff --git a/lib/jsdom/browser/Window.js b/lib/jsdom/browser/Window.js
index 52d011cae61c3688ec64baa5cec411d55edbda9d..298d7ec8d2cc1ea5e974262b978e6041389900f7 100644
--- a/lib/jsdom/browser/Window.js
+++ b/lib/jsdom/browser/Window.js
@@ -507,8 +507,8 @@ function installOwnProperties(window, options) {
// [LegacyUnforgeable]:
window: { configurable: false },
document: { configurable: false },
- location: { configurable: false },
- top: { configurable: false }
+ location: { configurable: true },
+ top: { configurable: false },
});
@maapteh Thanks, I updated the gist.
Maybe its handy to keep every version isolated, not many people need to stay latest. Thank you for your work! Hopefully something better will arrive with Jest :)
FYI this no longer seems to work on jsdom 27.4.0 (of course line numbers have changed, but I mean the patch in general doesn't work anymore). Despite setting configurable to true, I get Error: Not implemented: navigation (except hash changes).
Edit: Never mind. My issue was that I had a direct dependency against jsdom. I removed it from my own package and just use jest-environment-jsdom which internally depends on jsdom.
Then you need to create this patch file patches/jest-environment-jsdom++jsdom+26.1.0.patch
(This will patch the jsdom that is inside jest-environment-jsdom)
diff --git a/node_modules/jest-environment-jsdom/node_modules/jsdom/lib/jsdom/browser/Window.js b/node_modules/jest-environment-jsdom/node_modules/jsdom/lib/jsdom/browser/Window.js
index 52d011c..5b29f5a 100644
--- a/node_modules/jest-environment-jsdom/node_modules/jsdom/lib/jsdom/browser/Window.js
+++ b/node_modules/jest-environment-jsdom/node_modules/jsdom/lib/jsdom/browser/Window.js
@@ -507,7 +507,7 @@ function installOwnProperties(window, options) {
// [LegacyUnforgeable]:
window: { configurable: false },
document: { configurable: false },
- location: { configurable: false },
+ location: { configurable: true },
top: { configurable: false }
});
And run npx patch-package
Put this into a
patchesfolder and add this configuration to yourpackage.json: