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

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

    With Enzyme 3, if you need to change an input value but don't need to fire the onChange function you can just do this (node property has been removed):

    wrapper.find('input').instance().value = "foo";

    You can use wrapper.find('input').simulate("change", { target: { value: "foo" }}) to invoke onChange if you have a prop for that (ie, for controlled components).

提交回复
热议问题