title: How to test es6 module that imports jquery with jsdom
body: <p>I am struggling to get mocha, jsdom, es6 modules with babel to play nice with jquery.</p>
  
  <p>Here's a module</p>
  
  <pre><code>// lib/dom.js
  import $ from 'jquery';
  
  const node = (tag)=&gt; $(`&lt;${tag} /&gt;`)
  
  export {
    node
  }
  </code></pre>
  
  <p>Here's a test</p>
  
  <pre><code>// test/dom.js
  import assert from 'assert';
  import { node } from '../src/lib/dom';
  
  describe('node(tag)', ()=&gt; {
    it('should return a Node', ()=&gt; {
      let img = node('img');
      assert(img.nodeName === 'IMG');
    });
  });
  </code></pre>
  
  <p>Here's the jsdom setup</p>
  
  <pre><code>// test/_setup.js
  var jsdom = require('jsdom');
  
  global.document = jsdom.jsdom('&lt;!doctype html&gt;&lt;html&gt;&lt;body&gt;&lt;/body&gt;&lt;/html&gt;');
  global.window = document.parentWindow;
  </code></pre>
  
  <p>The script to run</p>
  
  <pre><code>mocha --compilers js:babel-register --recursive
  </code></pre>
  
  <p>What do I need to change to allow jsdom to load jquery so that dom.js can load the jquery module without getting the error:</p>
  
  <p>Error: jQuery requires a window with a document</p>
  
  <p>Here's the full source <a href="https://github.com/markbrown4/test-simple">https://github.com/markbrown4/test-simple</a></p>