I import noop
from lodash:
I set a function passed to onClick
as that noop
in defaultProps:
//Component.jsx
import { noop } from 'lodash';
const Component = ({onClickHandler}) => {
return <Button onClick={onClickHandler}>Click me</Button>
}
Component.defaultProps = { onClickHandler: noop }
How to test in RTL that render() gives us on onClickHandler which is noop? I already tried:
const noopSpy = jest.spyOn(require('lodash'), 'noop');
...
expect(noopSpy).toHaveBeenCalled()
expect(props.onClickHandler).toBe(noop)