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

后端 未结 16 2128
面向向阳花
面向向阳花 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:16

    None of the solutions above worked for me because I was using Formik and I needed to mark the field "touched" along with changing the field value. Following code worked for me.

    const emailField = orderPageWrapper.find('input[name="email"]')
    
    emailField.simulate('focus')
    emailField.simulate('change', { target: { value: 'test@example.com', name: 'email' } })
    emailField.simulate('blur')
    

提交回复
热议问题