Enzyme - How to access and set <input> value?

后端 未结 16 2151
面向向阳花
面向向阳花 2020-12-07 22:06

I\'m confused about how to access value when using mount. Here\'s what I\'ve got as my test:

  it(\'cancels changes w         


        
16条回答
  •  余生分开走
    2020-12-07 22:34

    In case anyone is struggling, I found the following working for me

    const wrapper = mount(); // component under test
    const textField = wrapper.find(TextField);
    
    textField.props().onChange({ target: { value: 'New Task 2' } })
    textField.simulate('change');
    // wrapper.update() didn't work for me, need to find element again
    
    console.log(wrapper.find(TextField).props()); // New Task 2
    

    It seems that you need to define what happens in the change event first and then simulate it (instead of simulating the change event with data)

提交回复
热议问题