title: Nightmare with Mocha: Uncaught TypeError: Cannot read property 'apply' of undefined
body: <p>I'm trying to run an example test with Nightmare.js and Mocha, and I keep getting the error above. Here is the full output:</p>
  
  <pre><code>$ mocha nightmare-chai-example.js 
  
  
    Nightmare demo
      Start page
        1) should show form when loaded
  
  
    0 passing (716ms)
    1 failing
  
    1) Nightmare demo Start page should show form when loaded:
       Uncaught TypeError: Cannot read property 'apply' of undefined
        at Nightmare.done (/home/user/testing/node_modules/nightmare/lib/nightmare.js:313:14)
        at Nightmare.next (/home/user/testing/node_modules/nightmare/lib/nightmare.js:291:35)
        at /home/user/testing/node_modules/nightmare/lib/nightmare.js:301:46
        at EventEmitter.&lt;anonymous&gt; (/home/user/testing/node_modules/nightmare/lib/ipc.js:93:18)
        at ChildProcess.&lt;anonymous&gt; (/home/user/testing/node_modules/nightmare/lib/ipc.js:49:10)
        at handleMessage (internal/child_process.js:695:10)
        at Pipe.channel.onread (internal/child_process.js:440:11)
  </code></pre>
  
  <p>And here is the code that I'm running:</p>
  
  <pre><code>var path = require('path');
  var Nightmare = require('nightmare');
  var should = require('chai').should();
  
  describe('Nightmare demo', function() {
    this.timeout(15000); // Set timeout to 15 seconds
  
    var url = 'http://example.com';
  
    describe('Start page', function() {
      it('should show form when loaded', function(done) {
        new Nightmare()
          .goto(url)
          .evaluate(function() {
            return document.querySelectorAll('form').length;
          }, function(result) {
            result.should.equal(1);
            done();
          })
          .run();
      });
    });
  });
  </code></pre>
  
  <p>From <a href="https://gist.github.com/MikaelSoderstrom/4842a97ec399aae1e024" rel="nofollow">this gist</a>.</p>
  
  <p>I'm running Ubuntu 16.04 LTS on an Oracle VM VirtualBox.</p>