Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

208
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda