Sometimes you need to write a code that utilizes global variables, such as document, window etc. This code is hard to test unless you mock global variables. I’m not saying that it is a bad thing to do, I just want to suggest another solution. Example Here’s a function accessing a…