Doing some headless testing using Mocha > Chai > PhantomJS. Everything is setup and working, but I'm trying to fill a form with bad credentials, and then check to see that a DOM element is created.
What I want to do is basically this:
it('should display error message string for bad credentials', function(done) {
page.evaluate(function() {
document.querySelector('input.form-input[type="text"]').value = 'foo@bar.com';
document.querySelector('input.form-input[type="password"]').value = 'wrongpass';
document.querySelector('input.form-action-b').click();
return document.querySelector('div.status-oops p').innerText;
}, function(result) {
result.should.equal('Username and password do not match.');
done();
});
});
But I'm getting: "Uncaught TypeError: Cannot read property 'should' of null"
...because div.status-oops isn't there yet. I get the same results in Chrome console, but if I then try to show the same text a few seconds later it works just fine.
Any ideas how to delay the return?