I have an element with an onClick
handler which may be disabled by adding pointer-events: none
to parent (parent disables children click).
Now I want to test that my child is not clickable, how can I do this?
Using userEvent.click
throws error:
Error: Unable to perform pointer interaction as the element has `pointer-events: none`:
But this is exactly what I am trying to test…
2
Answers
You can use the
pointerEventsCheck
option ofuserEvent.click
, which allows you to control how often the pointer events check is performed.For example:
You could use
expect().toThrow()
as documented here.Depending on your test setup, you could also pass your
onClick
a mocked function and assert that it is never called.