Last active
May 26, 2019 14:35
-
-
Save prmishra/829618e818073c2a792318b56be4be27 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const jsdom = require("jsdom"); | |
const { JSDOM } = jsdom; | |
const dom = new JSDOM(`<body></body>`, { runScripts: "dangerously" }); | |
function createDom(total) { | |
for (var i = 0; i < total; i++) { | |
var btn = dom.window.document.createElement('button'); | |
btn.appendChild(dom.window.document.createTextNode('Button ' + i)); | |
btn.addEventListener('click', function(){ console.log(i); }); | |
dom.window.document.body.appendChild(btn); | |
} | |
} | |
function testDom(which) { | |
var evt = dom.window.document.createEvent("HTMLEvents"); | |
evt.initEvent("click", false, false); | |
dom.window.document.body.children[which].dispatchEvent(evt); | |
} | |
var args = process.argv.slice(2); | |
createDom(args[0]) | |
testDom(args[1]) | |
// node script.js 5 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
const jsdom = require("jsdom");
const { JSDOM } = jsdom;
const dom = new JSDOM(
<body></body>
, { runScripts: "dangerously" });function createDom(total) {
for (let i = 0; i < total; i++) {
var btn = dom.window.document.createElement('button');
btn.appendChild(dom.window.document.createTextNode('Button ' + i));
btn.addEventListener('click', function(){ console.log(i); });
dom.window.document.body.appendChild(btn);
}
}
function testDom(which) {
var evt = dom.window.document.createEvent("HTMLEvents");
evt.initEvent("click", false, false);
dom.window.document.body.children[which].dispatchEvent(evt);
}
var args = process.argv.slice(2);
createDom(args[0])
testDom(args[1])
// node script.js 5 0