Simply saying I want to assert clicking on this button without onClick prop will result in an error(I know this is a silly case but this is just a rough simplification). But unfortunately I cannot catch this error, no matter how I tried.
The pseudocode looks like this:
Element.js:
const Element = ({ onClick }) => (
<button onClick={() => onClick('test')}>Test</button>)
);
Element.test.js
it('triggers on click callback', () => {
const wrapper = render(<Element />);
expect(userEvent.click(wrapper.getByTestId('test'))).toThrowError();
});
I receive 3 console.error statements: "console.error Error: Uncaught [TypeError: onClick is not a function]"
and a
expect(received).toThrowError()
Received function did not throw
This doesn't make much sense to me. Please help me find a solution or at least clarify what is happening