fireEvent.mouseOver document.createRange is not a function

Viewed 953

I am unable to use fireClick.mouseOver(tab) using for testing tooltip on tab hover.

Below is the code snippet.

  it('should handle change on hover of tab', () => {

    const {getByTestId, getByRole} = renderComponent('Draft');
    const tab0 = getByTestId('tab-0');
    fireEvent.mouseOver(tab0);

    expect(getByRole('tooltip')).not.toBeNull();
  } 

I am getting exception as "document.createRange is not a function"

However fireEvent.click(tab) is working good.

1 Answers

One reason you might be getting the error is because role="tooltip" is nowhere to be found in the DOM meaning either the HTML node does not exist or the property role is absent.

If it exists, then update jest to 26+ for instance: "jest": "^26.4.2" which should clear the issue

Related