Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
29 lines (24 sloc) 1.27 KB

then...catch

The internal .then() method to Nightmare does not work precisely like native Promise .then(), instead always opting to take the success and rejection callback for the promise. This was probably done to make sure vo, co, and possibly mocha-generators would work nicely with Nightmare.

The side effect of this is minor, causing exceptions internal to .then() to behave differently to their Promise counterparts. Consider:

var Nightmare = require('nightmare');
var nightmare = Nightmare();
nightmare
  .goto('http://example.com')
  .wait('body')
  .evaluate(function() {
    return document.title;
  })
  .then(function(title) {
    console.oops(title);
  }, function(err) {
    console.log('second argument error');
  });

In an ordinary promise, the rejection argument would not get called, yet in Nightmare, it does.

Solution

Alter the .then() implementation to call .then(fulfill, reject) instead of .then(fulfill).catch(reject). As yet, PR is unsubmitted.

References

You can’t perform that action at this time.