title: How can I fix "ReferenceError: $ is not defined" when using jQuery with mocha-jsdom?
body: <p>I'm setting up ES6 unit tests in my project and I am having some trouble making them work with libraries. I thought I'd use jQuery just as a test to try and make it work. Without libraries, the tests work. </p>
  
  <p>Note that jQuery is imported into my main.js file so it is available throughout the project. </p>
  
  <p>My JS file looks like this:</p>
  
  <pre><code>class Test {
    constructor(options) {
      this.init();
    }
  
    init() {
      $('.test-div').addClass('test');
    }
  
    sayHello() {
      return 'hello world!';
    }
  }
  
  export default Test;
  </code></pre>
  
  <p>And the test looks like this:</p>
  
  <pre><code>import jsdom from 'mocha-jsdom';
  import chai from 'chai';
  import Test from './test';
  
  chai.should();
  
  describe('Frequency', () =&gt; {
  
    var $;
    jsdom();
  
    before(() =&gt; {
      $ = require('jquery');
    })
  
    it('should output hello world', () =&gt; {
        const test = new Test();
        test.sayHello().should.equal('hello world!');
    });
  
  });
  </code></pre>
  
  <p>If I remove the <code>init()</code> function, the test works. However, the before function doesn't seem to import jQuery for the test. The error I receive in the console is as follows:</p>
  
  <pre><code>ReferenceError: $ is not defined
    at Frequency.init
  </code></pre>