Here is a real-world example that I am using:
How to Use Nightmare.js without ES6 Syntax and Yield
However, when I include it in a Mocha test, it times out. Here's the code snippet:
describe('Google', function() {
it('should perform tasks', function(done) {
var startTime = Date.now();
var nightmareInstance = Nightmare();
Promise.resolve(nightmareInstance
.goto('http://google.com')
.evaluate(function() {
return document.getElementsByTagName('html')[0].innerHTML;
}))
.then(function(htmlContent) {
console.log("Execution time: " + (Date.now()-startTime) + "ms");
console.log("Result:", htmlContent);
expect(htmlContent).to.equal('abc');
done();
return nightmareInstance.end();
}).then(function(result) {
}, function(error) {
console.error(error); // throwing an error here won't work
});
});
});
The issue lies in the fact that done()
is never invoked.