import TestRenderer from 'react-test-renderer';class MyComponent extends React.Component {
constructor(props) {
super(props);
this.input = null;
}
componentDidMount() {
this.input.focus();
}
render() {
return this.input = el} />
}}let focused = false;TestRenderer.create(
,
{
createNodeMock: (element) => {
if (element.type === 'input') { // mock a focus function
return {
focus: () => {
focused = true;
}
};
}
return null;
}
});expect(focused).toBe(true);