Answer the question
In order to leave comments, you need to log in
How to test components that are described via arrow functions?
Hello!
The problem is this: I described the component through an arrow function
const Form = (props) => {
<div>
<Button onClick={() => func1}>Компонента Кнопка 1</Button>
<Button onClick={() => func2}>Компонента Кнопка 2</Button>
</div>
}
const instance = TestUtils.renderIntoDocument(<Form />);
Answer the question
In order to leave comments, you need to log in
I found a solution and it turned out to be simple.
To test such components, you can create a TestWrapper component
import React, {Component, PropTypes} from 'react';
export default class TestWrapper extends Component {
constructor(props) {
super(props);
}
render() {
return React.Children.only(this.props.children);
}
}
TestWrapper.propTypes = {
children: PropTypes.node.isRequired
}
const instance = TestUtils.renderIntoDocument(<TestWrapper><Form /></TestWrapper>);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question