I was following all the instructions for the newest version of @testing-library/user-event
.
BEFORE:
test('request support action',() => {
render(<SupportSection requestSupport={requestSupport} />);
const button = screen.getByRole('button');
userEvent.click(button);
expect(requestSupport).toHaveBeenCalled();
});
AFTER:
test('request support action', async () => {
const user = userEvent.setup();
render(<SupportSection requestSupport={requestSupport} />);
const button = screen.getByRole('button');
await user.click(button);
expect(requestSupport).toHaveBeenCalled();
});
requestSupport
is mocked in the higher scope const requestSupport = jest.fn();
The error I'm getting is:
TypeError: range.cloneRange is not a function
All my tests were passing before the library updates, now all failing.
I finally found the solution, the error occured due to some old mock, that previous test environment required. All that must be done, was to remove below from jest config file:
global.document.createRange = () => ({ ... });