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
if it failed to be deleted.

Relevant jest issue - jestjs/jest#3152

Relevant node pr - nodejs/node#11266
  • Loading branch information
gdborton committed Mar 23, 2017
1 parent bdff1b8 commit cc05b8a
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,11 @@ export function withSetStateAllowed(fn) {
fn();
if (cleanup) {
delete global.document;
// 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.
if (global.document) {
global.document = undefined;
}
}
}

Expand Down

0 comments on commit cc05b8a

Please sign in to comment.