Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

411
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda