-
Couldn't load subscription status.
- Fork 39
Description
First of all, thanks for the interesting and useful solution, which jsdom-global definitely is.
Though let me notice there is still a difference between the real browsers behavior and the environment emulated on the node using jsdom-global. In the real browser:
window.foo=1;
typeof foo; // => 'number'
Unfortunately in the emulated environment on node -r jsdom-global/register:
window.foo=1;
typeof foo; // => 'undefined'
Let me ask - is it possible to fix the above disadvantage?
I have the impression that identifing window with global seems to be easy achievable by changing in the jsdom-global/index.js only the little piece of the existing code:
KEYS.forEach(function (key) {
global[key] = window[key]
})
global.document = window.document // change
global.window = window // change
window.console = global.console // change
document.destroy = cleanup
as follows:
KEYS.forEach(function (key) {
global[key] = window[key]
})
global.window=global // changed
document.window=global // changed
document.destroy = cleanup
Now in the emulated environment on node -r jsdom-global/register we have
window.foo=1;
typeof foo; // => 'number'
Unfortunately it is not the correct solution - for example after the change the window.DOMParser lost, though DOMException, DOMImplementation or DOMTokenList are available as globally as well as the window members...
(I suppose the cleanup behavior may also require some tuning because after the proposed change it could be the "one way ticket")