M
M
Maxim2015-08-18 16:31:36
React
Maxim, 2015-08-18 16:31:36

Why doesn't TestUtils.Simulate.change work in react tests?

Hello. The previous question is related to the same, but he did not dare.
Component:

import React, { Component } from 'react';

export default class Test extends Component {

  constructor(...props) {
    super(...props);
  }

  render() {
    return (
      <div><input ref="input" /></div>
    )
  }
}

Test code:
describe("Broker Full Page", function() {

  let page;

  beforeEach(function() {
    page = TestUtils.renderIntoDocument(<BrokerFull />);
  });

  it("Change all inputs in BrokerFull page", function() {
    let input = TestUtils.findRenderedDOMComponentWithTag(page, "input");
    expect(input.getDOMNode().value).to.be.equal('');   //  PASSED
    TestUtils.Simulate.change(input, { target: { value: 'a' } });
    expect(input.getDOMNode().value).to.be.equal('a');  // FILED
  });

});

When you try to change the value in the input field, nothing changes.
What am I doing wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
tamtakoe, 2016-09-29
@tamtakoe

The React documentation says how to do it https://facebook.github.io/react/docs/test-utils.html

// <input ref="input" />
var node = this.refs.input;
node.value = 'giraffe';
ReactTestUtils.Simulate.change(node);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question