onChange - Testing using Jest Enzyme - check?

余生颓废 提交于 2019-12-11 18:06:45

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!