Created
April 15, 2019 15:54
-
-
Save frosas/d9f34bf3e1a3927c297e17cf2227041e to your computer and use it in GitHub Desktop.
setupGlobalDom()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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