Using @testing-library/react and @testing-library/user-event with vitest's browser mode? #6585
-
Hey, I'm currently trying to enable browser mode for a codebase i'm working on since simulated envs (currently on Now I have a huge set of test suites, speaking like 14k. Trying browser mode out I noticed that using it('should be able to display tooltip', async () => {
setup({ tooltip: 'Tooltip', tooltipPosition: 'top' });
await userEvent.hover(screen.getByRole('button'));
await screen.findByText('Tooltip');
}); fails when importing Now my question is, is it possible to keep using Another question I have is how would I test the following scenario using browser mode?: it('should support disabled', async () => {
setup({ disabled: true });
await userEvent.click(screen.getByRole('button'));
expect(onClick).not.to.have.been.called;
}); This works using The setup is a bit complex to replicate tbh, the codebase is just huge, but I was wondering if anyone could provide some guidance here. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
await userEvent.hover(screen.getByRole('button').element());
You can disable actionability checks by providing await userEvent.click(screen.getByRole('button'), { force: true }); |
Beta Was this translation helpful? Give feedback.
screen.getByRole
returns aLocator
, not the HTML Element. You can call.element()
or.query()
to return the HTML element itself to pass it down to@testing-library/user-event
:You can disable actionability checks by providing
force: true
as an option to.click
: