title: How to mock window/document with mocha/chai
body: <p>When I try to unit test the <code>getElement</code> function</p>
  
  <pre><code>class BarFoo {
      getElement() {
          return document.querySelector('#barfoo');
      }
  }
  </code></pre>
  
  <p>mocha doesn't know anything about <code>document</code>, so I figured that you might do something like this:</p>
  
  <pre><code>beforeEach(() =&gt; {
      global.document = {
          querySelector: () =&gt; { ... }
      }
  }
  </code></pre>
  
  <p>Although this works, I'm wondering if this is the correct approach and maybe there is a package available to solve this issue, because my approach can get laborious if more browser API's are used ?</p>