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

105
Views
Enzyme testing a click with an event as parameter

'I am trying to test out this code using enzyme. I want to simulate a click but i get an error "Reference Error, Event is not defined". How do i get past that? Do i need to mock the function?'

const handleClick = (event : any) => {
  setAnchorEl(event.target);
  setOpen(true);
};
<IconButton onClick={() => handleClick(event)}>
  <DeleteIcon className={classes.threeDotsIcon}/>
</IconButton>

I tried simulating the click like this but it gives me an error, event is not defined.

'''

let wrapper = mount(<Provider store={store1}><MyComponent{...mockProps} /></Provider>);
let button = wrapper.findWhere(elem => elem.name() === 'IconButton');
button.simulate('click');'''
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You forgot to pass the event to handleClick event handler, onClick={(event) => handleClick(event)}. And you need to pass a simulated click event object like this button.simulate('click', { target: 'whatever' })

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!