Never fully hiding in Jest tests
See original GitHub issueIt 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:
- Created 3 years ago
- Reactions:5
- Comments:26 (10 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@atomiks could someone of you guys take a look at this? would be great to have those hiding tests for Tippy-based components. Thanks 😃
@cscheffauer Could you share what was the issue ? I’m also facing it right now 😅