How to simulate click on child element using enzyme and sinon?

Viewed 10368

I am using using enzyme and sinon, I receive this error when trying to use this test case:

Expected value to equal: true Received: false

In console when using .debug() I see:

Apparently event handler for click is not being called.

I suspect the issue could be related to .simulate('click', onLocationClick).

Could you please help me out and tell what I am doing wrong here? Thanks.

 console.log src\forecast\locationFinder\LocationFinder.test.js:28
      <Location country="CZ" id={3067696} name="Prague" onLocationClick={[Function]} />

  it('should click event', () => {
    const data = [
      {
        country: 'CZ',
        id: 3067696,
        name: 'Prague'
      },
      {
        country: 'US',
        id: 4548393,
        name: 'Prague'
      }
    ]
    const onLocationClick = sinon.spy()
    const wrapper = shallow(
      <LocationFinder
        locations={data}
        onLocationClick={onLocationClick}
    />)
    console.log(wrapper.find({ id: 3067696 }).debug())
    wrapper.find({ id: 3067696 }).simulate('click', onLocationClick)
    expect(onLocationClick.called).toEqual(true)
  })

2 Answers
Related