'Error in Jest Test with Vanilla Javascript: expect(jest.fn()).toBeCalledWith(...expected) Expected: "click", Any<Function> Number of calls: 0
Looks like click method is not getting triggered I have tried evreything, it would be appreciated if someone knows the answer I'm getting this error: expect(jest.fn()).toBeCalledWith(...expected)
Expected: "click", Any
Number of calls: 0
Not sure what I'm doing wrong here. Does anyone know how to resolve this issue.
Here is my app.js file
function display() {
displayTable.style.display = "block"
obj.move.push(input.value);
let bulldozerMove = obj.move[obj.move.length - 1];
let index = obj.initPos[obj.initPos.length - 1];
let direction = obj.initDir[obj.initDir.length - 1];
solution(
grid,
index,
direction,
bulldozerMove
);
let newRow = displayTable.insertRow(-1);
key.forEach((val) => {
let insertData = obj[val];
for (let i = 0; i < 1; i++) {
let newCell = document.createElement("td");
newCell.style.border = 'solid 1px black';
newCell.appendChild(document.createTextNode(insertData[insertData.length - 1]));
newRow.appendChild(newCell);
}
tableBody.appendChild(newRow);
})
displayTable.appendChild(tableBody);
document.body.appendChild(displayTable);
}
function main(){ button.addEventListener("click", display);}
main();
const exportFunctions = {
getNextPos,
solution,
main,
display
};
module.exports = exportFunctions;
Here is my app.test.js file
const app = require('./app');
test("It should pass", () => {
const instanceMock = jest.spyOn(app, "display");
button.addEventListener = jest
.fn()
.mockImplementationOnce((event, callback) => {
callback();
});
app.main();
expect(button.addEventListener).toBeCalledWith(
"click",
expect.any(Function)
);
expect(instanceMock).toBeCalledTimes(1);
});
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
