Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@frosas
Created April 15, 2019 15:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frosas/d9f34bf3e1a3927c297e17cf2227041e to your computer and use it in GitHub Desktop.
Save frosas/d9f34bf3e1a3927c297e17cf2227041e to your computer and use it in GitHub Desktop.
setupGlobalDom()
const setupGlobalDom = () => {
const originalDocument = global.document;
const originalWindow = global.window;
global.document = jsdom('');
global.window = global.document.defaultView;
return () => {
global.document = originalDocument;
global.window = originalWindow;
}
}
const useGlobalDom = callback => {
const teardownGlobalDom = setupGlobalDom();
try {
return callback();
} finally {
teardownGlobalDom();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment