Simulating text entry with reactJs TestUtils

前端 未结 2 1856
伪装坚强ぢ
伪装坚强ぢ 2021-02-19 07:11

I want to be able to simulate a user typing into a text box using reactjs so that I can test my validation status messages.

I have a react component which validates on k

相关标签:
2条回答
  • 2021-02-19 07:21

    I found that this syntax works better for me:

      const emailInput = component.refs.userEmailInput;
      emailInput.value = 'test@gmail.com';
      Simulate.change(component.refs.userEmailInput);
    

    The second line updates the input with the text, 'test@gmail.com'. The last line triggers the change.

    0 讨论(0)
  • 2021-02-19 07:35

    By setting nameInput.props.value = 'a'; you are not actually updating the value in your component.

    You should use React.addons.TestUtils.Simulate.change(nameInput, { target: { value: 'a' } }); or something similar to simulate modifying the actual value.

    0 讨论(0)
提交回复
热议问题