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

209
Visualizações
Jest test causing a 'synthetic event' error when checking a spied on function was called with an object containing 'currentTarget'

I have a function like this:

const doThingWithTarget = (event, someBoolean) => {
  if(someBoolean) otherFunction(event.currentTarget); // uses currentTarget
}

// more code ...

return (<Button onClick={event => doThingEithEvent(event, true)}>Click me!</Button>)

And I am having to test this button was called clicked, and I wanted to make sure the first argument has a currentTarget:

expect(doThingWithTarget).toHaveBeenCalledWith(
  expect.objectContaining({ currentTarget: expect.any(Function) }), true,
);

But react is detecting me accessing the currentTarget on the synthetic element and throwing an error.

How can I avoid that? It shouldn't be erroring.

about 4 years ago · Santiago Trujillo
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