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

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

    I think what you want is:

    input.simulate('change', { target: { value: 'Hello' } })
    

    Here's my source.

    You shouldn't need to use render() anywhere to set the value. And just FYI, you are using two different render()'s. The one in your first code block is from Enzyme, and is a method on the wraper object mount and find give you. The second one, though it's not 100% clear, is probably the one from react-dom. If you're using Enzyme, just use shallow or mount as appropriate and there's no need for render from react-dom.

提交回复
热议问题