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

206
Views
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
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!