I use an enzyme to test my reactive components. I have a stateless component that has an internal function. How can I call and check this internal function?
Here is my component:
const Btn = (props) => { const types = ['link', 'plainLink', 'primary', 'secondary', 'danger', 'info']; const handleClick = (event) => { event.preventDefault(); props.onClick(event); }; return ( <button onClick={handleClick} className={classes}> <span>{props.children}</span> </button> ); };
I tried the following, but I get an error: TypeError: undefined is not a constructor
const btnComp = shallow(<Btn />); btnComp.instance().handleClick();
javascript function reactjs testing enzyme
Ian
source share