Skip to content

Commit cc05b8a

Browse files
committed
Fix an issue w/ cleaning up global.document.
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
1 parent bdff1b8 commit cc05b8a

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

src/Utils.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,11 @@ export function withSetStateAllowed(fn) {
222222
fn();
223223
if (cleanup) {
224224
delete global.document;
225+
// This works around a bug in node/jest in that developers aren't able to
226+
// delete things from global when running in a node vm.
227+
if (global.document) {
228+
global.document = undefined;
229+
}
225230
}
226231
}
227232

0 commit comments

Comments
 (0)