Wednesday 20 June 2018

Is it possible to have more than 1 global script environment?

While writing tests(i used Jest), i stumbled into thing part of the code that worked fine when not testing, but broke when running from Jest.Problem was in this line(yes i know that Array.isArray exists).if (someVariable.constructor === Array) { // something} What happed is that while someVariable was actually an array, check failed, instanceof returned false too, but debugger and Array.isArray confirmed that it is actually an array Array. I even went ahed, and comparedsomeVariable.__proto__.__proto__ === Object Wich resulted in false. I googled for a bit, and found this articleBasically what it is sayng that in browser JS, there could be more than one window instance. Wich also results in false, when comparing 2 constuctors from diffrent window environment.So it might be, that i have similar porblem, but in node. Can something like 2 global environment be done?Thank you!

Submitted June 20, 2018 at 03:26PM by SandOfTheEarth

No comments:

Post a Comment