0

With prior versions of react-tooltip, I was able to simply render the tooltip without even having to trigger a user interaction, with v5.28, even with userEvents, I am still unable to get the tooltip div to appear.

  it('should render tooltip', async () => {
const user = userEvent.setup();

const SampleComponent = () => (
  <>
    <div
      data-tooltip-id="sample-tooltip"
      data-tooltip-content="Test Tooltip popup"
      role="button"
      data-testid="sample-field-help"
    >
      Tooltip Content
    </div>
    <ReactTooltip
      id="sample-tooltip"
      role="tooltip"
      delayShow={100}
      clickable
      globalCloseEvents={{ clickOutsideAnchor: true, scroll: true }}
      openOnClick
      render={
        dataTip => (
          <div className="tooltip-content" data-testid="tooltip-content">
            <div className="tooltip-text" data-testid="tooltip-text">
              {dataTip.content}
            </div>
          </div>
        )
      }
    />
  </>
);

render(<SampleComponent />);
const anchorElement = screen.getByTestId('sample-field-help');
await user.click(anchorElement);

// none of the below works
// await user.hover(anchorElement);
// await userEvent.dblClick(anchorElement);

screen.debug()
  });
2
  • What debug details did you get by running screen.debug()? Commented Jan 22 at 2:38
  • The issue was solved, but the initial debug rendered just the sibling div. Commented Jan 23 at 3:31

1 Answer 1

0

Mocking window.ResizeObserver caused the tooltip to render.

 window.ResizeObserver =
  window.ResizeObserver ||
  jest.fn().mockImplementation(() => ({
    disconnect: jest.fn(),
    observe: jest.fn(),
    unobserve: jest.fn(),
  }));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.