question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Never fully hiding in Jest tests

See original GitHub issue

It seems like Tippy never actually hides and unmounts when using jest + testing-library. onHide is called, but the test fails on waitForElementToBeRemoved and onHidden is also never called.

import React from 'react';
import * as test from '@testing-library/react';
import Tippy from '@tippyjs/react';

it('should hide', async () => {
  const onHide = jest.fn();
  const onHidden = jest.fn();
  const { rerender, queryByText } = test.render(
    <Tippy content="foo" onHide={onHide} onHidden={onHidden} visible />,
  );
  expect(queryByText('foo')).toBeInTheDocument();
  rerender(<Tippy content="foo" onHide={onHide} onHidden={onHidden} visible={false} />);
  expect(onHide).toHaveBeenCalled();
  await test.waitForElementToBeRemoved(() => queryByText('foo'));
  expect(onHidden).toHaveBeenCalled();
});
  ● should hide

    Timed out in waitForElementToBeRemoved.

      12 |   rerender(<Tippy content="foo" onHide={onHide} onHidden={onHidden} visible={false} />);
      13 |   expect(onHide).toHaveBeenCalled();
    > 14 |   await test.waitForElementToBeRemoved(() => queryByText('foo'));
         |              ^
      15 |   expect(onHidden).toHaveBeenCalled();
      16 | });
      17 |

      at Object.waitForElementToBeRemoved (../node_modules/@testing-library/dom/dist/wait-for-element-to-be-removed.js:22:24)
      at Object.<anonymous> (__tests__/tippy.test.tsx:14:14)

Version: 4.1.0 TippyJS version: 6.2.6

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:5
  • Comments:26 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
cscheffauercommented, May 27, 2021

@atomiks could someone of you guys take a look at this? would be great to have those hiding tests for Tippy-based components. Thanks 😃

1reaction
Okazaricommented, Jan 26, 2022

@cscheffauer Could you share what was the issue ? I’m also facing it right now 😅

Read more comments on GitHub >

github_iconTop Results From Across the Web

6 Ways to Run Jest Test Cases Silently - Medium
1. Turn Off All Console Information. If using Jest test framework, you can turn off all console messages by one command: jest --silent...
Read more >
Developers - Never fully hiding in Jest tests - - Bountysource
Never fully hiding in Jest tests. ... It seems like Tippy never actually hides and unmounts when using jest + testing-library.
Read more >
Unit Testing in React: Full Guide on Jest and Enzyme Testing
Discover how to start and proceed with the testing of React components with Enzyme and Jest if you do not have enough experience...
Read more >
JQuery check for element visibility in jest tests - Stack Overflow
I'm using .is(":visible") to do that and in unit test it always reports that the element is hidden but it works fine in...
Read more >
How to use React Testing library to wait for async elements, a ...
You have added a Jest spyOn to the window.fetch function call with a mock implementation. This mock implementation checks if the URL passed...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found