2

I am using Jest to test a ReactJS app. How can one test if the view controller has the necessary child components present.

For example, here is an example of the view controllers' render function:

// App.js
render: function() {
  var table;
  if (this.state.showResults) {
    table = <Table {...this.state} />
  }

  return (
    <div>
      <Form />
      {table}
  )
}

For HTML elements, something like will do:

button = TestUtils.findRenderedDOMComponentWithTag AppElement, 'button'

How can I do the same for the Form or Table components ?

Thank you!

4

1 回答 1

3

Doh ...所以答案是findRenderedComponentWithType。

首先,我需要组件类:

Form = require('Form.react.js');

然后我将其作为参数传递,例如:

form = TestUtils.findRenderedComponentWithType(AppElement, Form);

当然在哪里

AppElement = TestUtils.renderIntoDocument(<App />)
于 2015-02-17T12:03:33.653 回答