Advertisement
Guest User

Untitled

a guest
Apr 25th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. const setupGlobalDom = () => {
  2. const originalDocument = global.document;
  3. const originalWindow = global.window;
  4. global.document = jsdom('');
  5. global.window = global.document.defaultView;
  6. return () => {
  7. global.document = originalDocument;
  8. global.window = originalWindow;
  9. }
  10. }
  11.  
  12. const useGlobalDom = callback => {
  13. const teardownGlobalDom = setupGlobalDom();
  14. try {
  15. return callback();
  16. } finally {
  17. teardownGlobalDom();
  18. }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement