skratchdot / react-bootstrap-multiselect

A multiselect component for react (with bootstrap). This is a react port of bootstrap-multiselect.
http://projects.skratchdot.com/react-bootstrap-multiselect/
Other
119 stars 62 forks source link

How to test multiselect dropdown on change event? #80

Open NilapuAnusha opened 6 years ago

NilapuAnusha commented 6 years ago

Hi, I am writing testcases using enzyme, mocha and chai. When I call onChange event for multiselect it is not firing call.

Here is my code:

First one

 it('change country selection', () => {
     const wrapper = mount(<SearchFormPanel {...props}/>)
     const onCountryChange = spy(wrapper.instance(), 'onCountryChange')
     wrapper.instance().forceUpdate()
     wrapper.find('input[type="checkbox"]')
     expect(onCountryChange).to.have.calledOnce
     expect(wrapper.state('selectedCountries')).to.contain('GB')
     onCountryChange.restore() 
 })

Second one

 it('change country selection', () => {
    const wrapper = mount(<SearchFormPanel {...props}/>)
    const onCountryChange = spy(wrapper.instance(), 'onCountryChange')
    wrapper.instance().forceUpdate()
    let checkboxNode = $($(wrapper.getDOMNode()).find('input[type="checkbox"]')[3])
    checkboxNode.prop('checked', true).change()
    expect(onCountryChange).to.have.calledOnce
    expect(wrapper.state('selectedCountries')).to.contain('GB')
    onCountryChange.restore()
 })

Is there any better way to find onChange event?