Skip to content

Commit

Permalink
Fix an issue w/ cleaning up global.document.
Browse files Browse the repository at this point in the history
Except in the most recent versions of node, developers are unable to delete
things from global when running code in a node vm.  This means that enzyme is
failing to clean up after itself when temporarily defining global.document for
setState calls.

This papers over the issue by explicitly setting global.document to undefined
before attempting to delete. If the delete succeeds, the undefined value will
be removed.

Relevant jest issue - jestjs/jest#3152

Relevant node pr - nodejs/node#11266
  • Loading branch information
gdborton committed Mar 24, 2017
1 parent bdff1b8 commit 9634269
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,9 @@ export function withSetStateAllowed(fn) {
}
fn();
if (cleanup) {
// This works around a bug in node/jest in that developers aren't able to
// delete things from global when running in a node vm.
global.document = undefined;
delete global.document;
}
}
Expand Down

0 comments on commit 9634269

Please sign in to comment.