JSDOM版本:0.6.5 Nitrous.io Cloud IDE环境
观察到的问题: 创建一个空窗口然后附加一个事件处理程序失败,异常跟踪:
TypeError: Cannot read property 'Node' of undefined
at Object.DOMWindow.addEventListener (/home/action/workspace/Projects/nodejs/node_modules/jsdom/lib/jsdom/browser/index.js:180:10)
at Request._callback (/home/action/workspace/Projects/nodejs/page_test_demo.js:22:14)
at Request.self.callback (/home/action/workspace/Projects/nodejs/node_modules/request/index.js:148:22)
at Request.EventEmitter.emit (events.js:98:17)
at Request. (/home/action/workspace/Projects/nodejs/node_modules/request/index.js:886:14)
at Request.EventEmitter.emit (events.js:117:20)
at IncomingMessage. (/home/action/workspace/Projects/nodejs/node_modules/request/index.js:837:12)
at IncomingMessage.EventEmitter.emit (events.js:117:20)
at _stream_readable.js:910:16
at process._tickCallback (node.js:415:13)
以下是相关代码段:
var window = jsdom.createWindow();
console.log(window);
window.addEventListener('load', function() {
console.log('Load event completed');
});
window.document = jsdom.jsdom(body);
谁能告诉我在这里错过了什么?
答案 0 :(得分:0)
您在评论中提到的问题已于7个月前修复,因此只要您拥有最新版本的JSDOM,就可以执行此操作:
var jsdom = require('jsdom');
var body = '<html><body></body></html>';
var document = jsdom.jsdom(body);
var window = document.createWindow();
window.addEventListener('load', function() {
console.log('Load event completed');
});