From 675847a99f1640c87df0a6187eeb34b90d903666 Mon Sep 17 00:00:00 2001 From: Ulrich-Matthias Schäfer Date: Mon, 12 Nov 2018 23:09:25 +0100 Subject: plumber differences between node and browser so that tests run on both --- src/utils/window.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'src/utils') diff --git a/src/utils/window.js b/src/utils/window.js index 9e51339..626fde3 100644 --- a/src/utils/window.js +++ b/src/utils/window.js @@ -7,3 +7,26 @@ export function registerWindow (win = null, doc = null) { globals.window = win globals.document = doc } + +const save = {} + +export function saveWindow () { + save.window = globals.window + save.document = globals.document +} + +export function restoreWindow () { + globals.window = save.window + globals.document = save.document +} + +export function withWindow (win, fn) { + saveWindow() + registerWindow(win, win.document) + fn(win, win.document) + restoreWindow() +} + +export function getWindow () { + return globals.window +} -- cgit v1.2.3