-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.spec.js
30 lines (27 loc) · 907 Bytes
/
index.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
const Nightmare = require('nightmare');
const assert = require('assert');
require('.')(Nightmare);
it('function exists', function () {
assert.strictEqual(typeof Nightmare.prototype.xpath, 'function');
});
it('test example', async () => {
var links = await Nightmare()
.goto('http://example.com/')
.xpath('//a[@href]', function (node) {
// We cannot return DOM element to nodejs,
// we must return serializable object or primitive.
// If function is omitted, node.toString() will be used.
return {
href: node.href,
innerText: node.textContent,
};
})
.then();
assert.strictEqual(links.length, 1);
assert.deepStrictEqual(links, [
{
href: 'https://www.iana.org/domains/example',
innerText: 'More information...',
},
]);
});