Created
April 15, 2019 17:05
-
-
Save sagar-more/60cf76b385d728bd21069740b4bc5ec6 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 (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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment