我正在尝试使用 Nightmare.js 和 Mocha 运行示例测试,但我不断收到上述错误。这是完整的输出:
$ mocha nightmare-chai-example.js
Nightmare demo
Start page
1) should show form when loaded
0 passing (716ms)
1 failing
1) Nightmare demo Start page should show form when loaded:
Uncaught TypeError: Cannot read property 'apply' of undefined
at Nightmare.done (/home/user/testing/node_modules/nightmare/lib/nightmare.js:313:14)
at Nightmare.next (/home/user/testing/node_modules/nightmare/lib/nightmare.js:291:35)
at /home/user/testing/node_modules/nightmare/lib/nightmare.js:301:46
at EventEmitter.<anonymous> (/home/user/testing/node_modules/nightmare/lib/ipc.js:93:18)
at ChildProcess.<anonymous> (/home/user/testing/node_modules/nightmare/lib/ipc.js:49:10)
at handleMessage (internal/child_process.js:695:10)
at Pipe.channel.onread (internal/child_process.js:440:11)
这是我正在运行的代码:
var path = require('path');
var Nightmare = require('nightmare');
var should = require('chai').should();
describe('Nightmare demo', function() {
this.timeout(15000); // Set timeout to 15 seconds
var url = 'http://example.com';
describe('Start page', function() {
it('should show form when loaded', function(done) {
new Nightmare()
.goto(url)
.evaluate(function() {
return document.querySelectorAll('form').length;
}, function(result) {
result.should.equal(1);
done();
})
.run();
});
});
});
从这个要点。
我在 Oracle VM VirtualBox 上运行 Ubuntu 16.04 LTS。