Invokes a function prop.
Note that in React 16.8+, .invoke
will wrap your handler with ReactTestUtils.act
and call .update()
automatically.
propName
(String
): The function prop that is invoked...args
(Any
[optional]): Arguments that is passed to the prop function
Any
: Returns the value from the prop function
class Foo extends React.Component {
loadData() {
return fetch();
}
render() {
return (
<div>
<button
type="button"
onClick={() => this.loadData()}
>
Load more
</button>
</div>
);
}
}
const wrapper = mount(<Foo />);
wrapper.find('button').invoke('onClick')().then(() => {
// expect()
});