-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Using React 16 createRef #1704
Copy link
Copy link
Closed
Description
I'm trying to reference new React 16 refs in my enzyme 3 tests so that I can call .simulate, etc on internal references.
Simplified example:
class MyComponent extends React.Component {
constructor(props) {
super(props);
this.textInput = React.createRef();
}
render() {
return (
<input ref={this.textInput} />
);
}
}
Test:
component = mount(<MyComponent />);
const input = component.instance().textInput.current;
input.simulate('change', { ... });
However I get errors like:
TypeError: component.instance(...).textInput.current.simulate is not a function
This is a simplified example so I'm not looking for alternate ways of finding the input - I'm curious if and how we can use and test using React 16 references?
Reactions are currently unavailable