-1

Getting some practice running tests with mocha chai and nightmare. Everything seems to work until I get into my evaluate block.

var Nightmare = require('nightmare'),
  should = require('chai').should()

describe('Frontend Masters', function() {
  this.timeout(20000);

  it('should show form when loaded', function(done) {
    var nightmare = new Nightmare({show: true})
    nightmare
      .goto('https://frontendmasters.com/')
      .wait('a[href*="https://frontendmasters.com/login/"]')
      .click('a[href*="https://frontendmasters.com/login/"]')
      .wait('#rcp_login_form')
      .evaluate(function() {
        return window.document.title;
      }, function(result) {
        result.should.equal('Login to Frontend Masters');
        done();
      })
      .run(function(){
        console.log('done')
      });
  });
});

I've thrown in console logs and it never makes it into the evaluate. I've tried passing in several selectors into my wait() function, but it doesnt seem to be having an effect. Only error I'm receiving is that my timeout has been exceeded. But it doesnt matter how long i set it for

ceckenrode
  • 4,543
  • 7
  • 28
  • 48
  • It doesn't seem to have anything to do with `evaluate`. If the `wait` timeout fails, then either the previous click didn't work or the site is broken. By the way, which of the two `wait` calls failed? – Artjom B. Aug 11 '16 at 18:58
  • 1
    Do you get any helpful output when running with environment variable DEBUG="nightmare*" ? – yoz Aug 11 '16 at 21:24

1 Answers1

1

What version of Nightmare are you using?

The signature for .evaluate() has changed, and I think that may be the source of your issues. The second function you're passing in - the one that used to be for handling the results of the evaluation - is actually getting passed as an argument to the first .evaluate() argument. In other words, the second argument is never run, done() is never called, and your test will time out.

Also worth mentioning: .run() is not directly supported. Use.then() instead.

Finally, let's modify your source to reflect the above to get you started:

var Nightmare = require('nightmare'),
  should = require('chai')
  .should()

describe('Frontend Masters', function() {
  this.timeout(20000);

  it('should show form when loaded', function(done) {
    var nightmare = new Nightmare({
      show: true
    })
    nightmare
      .goto('https://frontendmasters.com/')
      .wait('a[href*="https://frontendmasters.com/login/"]')
      .click('a[href*="https://frontendmasters.com/login/"]')
      .wait('#rcp_login_form')
      .evaluate(function() {
        return window.document.title;
      })
      .then(function(result) {
        result.should.equal('Login to Frontend Masters');
        console.log('done')
        done();
      })
  });
});
Ross
  • 2,448
  • 1
  • 21
  • 24