Skip to content

Instantly share code, notes, and snippets.

@rdohms
Created June 8, 2016 08:51
Show Gist options
  • Save rdohms/9b659aba018fdefd20682f2df067970c to your computer and use it in GitHub Desktop.
Save rdohms/9b659aba018fdefd20682f2df067970c to your computer and use it in GitHub Desktop.
Writing tests
require('mocha-generators').install();
var path = require('path');
var Nightmare = require('nightmare');
var expect = require('chai').expect;
describe('AmsterdamPHP Raffler', function () {
this.timeout(15000); // Set timeout to 15 seconds, instead of the original 2 seconds
var url = 'http://localhost:8080',
nightmare;
beforeEach(function *() {
nightmare = Nightmare({
show: true
});
});
afterEach(function *() {
yield nightmare.end();
});
describe('Event List', function () {
it('should show a list of current/past events', function *() {
var x;
var result = yield nightmare
.goto(url)
.evaluate(function (x) {
//return document.querySelectorAll('ul.meetups > li').length; // evaluates to 95
return document.querySelectorAll('ul.meetups > li');
});
expect(result.length).to.be.above(1); // length undefined
});
});
});
@rdohms
Copy link
Author

rdohms commented Jun 8, 2016

What magic is the evaluate function doing, and how can i get something to return there that i can do 2 checks on it:

  • length
  • is the data-date attr of each li hight then x

@marfillaster
Copy link

You also need * after the function keyword when yield is called inside the function block

@rdohms
Copy link
Author

rdohms commented Jun 8, 2016

so for reference: evaluate serializes return into json, hence all properties go bye bye.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment