问题
I am trying to test onChange for the following code: using Jest / Enzyme The test is passing but coverage does not change, any reason ? file.js
<div className='tab-input-container'>
<select className='shape-dropdown' onChange={this.handleChange} name='category' defaultValue={!this.props.defaultData.category.$.id ? 'default' : this.props.defaultData.category.$.id}>
{categories}
</select>
file.test.js
Am I missing something? On change is being called 4 times. Here is just one example
it('should call the handleChange() function and change the state', () => {
const value = 'someValue';
wrapper.setState({
localState: {}
});
wrapper.instance().handleChange('someName')({ target: { value, name } });
expect(wrapper.state('someName')).toEqual(value);
});
ERROR: Cannot read property 'name' of undefined.
I added a console.log
right under handleChange
method: it is getting call because console log is returning ' SomeName'
来源:https://stackoverflow.com/questions/54789468/onchange-testing-using-jest-enzyme-check