Skip to content

Commit

Permalink
JSOM: ensure props on window can be restored
Browse files Browse the repository at this point in the history
Some new property descriptors has been changed so that
configurable=false. This broke the tests.

Additionally, doing two calls to configure the props
also exposed issues, so simply doing it in one call,
as in the original Enzyme docs.
  • Loading branch information
fatso83 committed May 13, 2023
1 parent ae61990 commit 12c21cf
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions integration-test/fake-clock-integration-test.js
Expand Up @@ -67,13 +67,21 @@ describe("globally configured browser objects", function () {
var dom = new jsdom.JSDOM("<!doctype html><html><body></body></html>");
var window = dom.window;

function makeMutable(descriptor) {
descriptor.configurable = true;
}

function copyProps(src, target) {
originalDescriptors = Object.getOwnPropertyDescriptors(target);
Object.defineProperties(
target,
Object.getOwnPropertyDescriptors(src)
const srcDescriptors = Object.getOwnPropertyDescriptors(src);
Object.keys(srcDescriptors).forEach((key) =>
// This is required to make it possible to remove/delete them afterwards
makeMutable(srcDescriptors[key])
);
Object.defineProperties(target, originalDescriptors);
Object.defineProperties(target, {
...srcDescriptors,
...originalDescriptors,
});
}

global.window = window;
Expand Down

0 comments on commit 12c21cf

Please sign in to comment.