i’m a complete beginner in when it comes to jsdom and i just want to know how to simulate the user typing the string and hitting solve button this is what i got so far
unitTest.js
suite("UnitTests", () => {
beforeEach(function () {
return JSDOM.fromFile(path.join(__dirname, "../views/index.html"), {
resources: "usable",
runScripts: "dangerously",
}).then((resolve) => {
window = resolve.window;
document = resolve.window.document;
textArea = document.getElementById("text-input");
error = document.getElementById("error");
solveButton = document.getElementById("solve-button");
});
});
suite("solver solve method", function () {
test("Valid puzzle strings pass the solver", function () {
const invalidPuzzleString =
"1.5..2.84..63.12.7.2..5.....9..1....8.2.367473.7.2..9.47...8..1..16....926614.478";
textArea.textContent = invalidPuzzleString;
solveButton.dispatchEvent(
new window.MouseEvent("click", { bubbles: true })
);
console.log(textArea.textContent);
console.log(error.innerHTML);
assert.equal(
error.innerHTML,
'<code>{ "error": "Puzzle cannot be solved" }</code>'
);
});
```