mardi 26 janvier 2016

React unit-test won't update value

I have a React component similar to this:

var Example = React.createClass({
  render: function() {
    return <input type="text"
      onChange  = {this.onChange}
      value     = {this.text}
      data-what = {this.text} />;
  }
});

I have a unit test in which I do this:

  1. Use TestUtils.renderIntoDocument to create the component, using "FIRST" as the state.text.
  2. Use Simulate.change to change the text to "SECOND".

How here's the weirdest thing. If I dump the HTML after each step, I expect to see:

<input type="text" data-what="FIRST" value="FIRST">
<input type="text" data-what="SECOND" value="SECOND">

…but for some bizarre reason, I keep getting these results:

<input type="text" data-what="FIRST" value="FIRST">
<input type="text" data-what="SECOND" value="FIRST">

In the second dump, value is still "FIRST". What??

Clearly the plumbing is working because data-what is correctly changed to "SECOND" but why isn't the value?? Very confused.

Aucun commentaire:

Enregistrer un commentaire