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

413
Views
simulate mouse click (pointerdown?) in js

I created this fork of this:

https://codesandbox.io/s/reactgrid-highlights-forked-shvr4z

I'm trying to write a test that selects a cell and edits it (jest). I didn't see that they export their test utils.

So I tried to select the cell, with no success. I downloaded their library, tried to debug their code and think they trigger pointerdown event when selecting a cell.

I tried to simulate it with:

const event = new PointerEvent('pointerdown')
myElement = document.querySelector('[data-cell-rowidx="1"][data-cell-colidx="0"]');
myElement.dispatchEvent(event);

Or other variations.

In addition, I tried with @testing-library/user-event:

userEvent.click(...)

pointer([
  {keys: '[MouseLeft>]', target: myElement},
  {keys: '[/MouseLeft]'},
])

Any help appreciated.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Succeeded!

const simulateMouseEvent = function(element, eventName, coordX, coordY) {
  element.dispatchEvent(new MouseEvent(eventName, {
    view: window,
    bubbles: true,
    cancelable: true,
    clientX: coordX,
    clientY: coordY,
    button: 0
  }));
};

const theButton = document.querySelector('[data-cell-rowidx="1"][data-cell-colidx="0"]')

const box = theButton.getBoundingClientRect(),
        coordX = box.left + (box.right - box.left) / 2,
        coordY = box.top + (box.bottom - box.top) / 2;

simulateMouseEvent (theButton, "pointerdown", coordX, coordY);
simulateMouseEvent (theButton, "pointerup", coordX, coordY);
simulateMouseEvent (theButton, "click", coordX, coordY);
about 4 years ago · Juan Pablo Isaza Report
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!