Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

405
Views
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);
  });
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!