Skip to content
This repository was archived by the owner on Nov 9, 2024. It is now read-only.

Commit bbbea98

Browse files
authored
test: check unmounting in tests (#309)
1 parent d4c915d commit bbbea98

File tree

4 files changed

+264
-43
lines changed

4 files changed

+264
-43
lines changed

babel.config.js

+8
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,12 @@ module.exports = {
44
'@babel/react',
55
],
66
plugins: ['annotate-pure-calls'],
7+
env: {
8+
test: {
9+
presets: [
10+
['@babel/env', {targets: {node: 'current'}}],
11+
'@babel/react',
12+
]
13+
}
14+
}
715
};

package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
],
3030
"jest": {
3131
"setupFilesAfterEnv": [
32-
"<rootDir>test/setup.js"
32+
"<rootDir>test/setup.js",
33+
"@testing-library/jest-dom/extend-expect"
3334
],
3435
"coveragePathIgnorePatterns": [
3536
"test/setup.js"
@@ -61,7 +62,8 @@
6162
"@babel/core": "^7.8.7",
6263
"@babel/preset-env": "^7.8.7",
6364
"@babel/preset-react": "^7.0.0",
64-
"@testing-library/react": "^8.0.1",
65+
"@testing-library/jest-dom": "^5.12.0",
66+
"@testing-library/react": "^11.2.7",
6567
"@types/react": "^16.8.2",
6668
"babel-eslint": "^10.0.1",
6769
"babel-jest": "^25.1.0",

test/Tippy.test.js

+26-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import React, {useRef, useState} from 'react';
22
import TippyBase from '../src';
3-
import {render, cleanup} from '@testing-library/react';
3+
import {
4+
render,
5+
screen,
6+
waitForElementToBeRemoved,
7+
} from '@testing-library/react';
48

59
jest.useFakeTimers();
610

7-
afterEach(cleanup);
8-
911
describe('<Tippy />', () => {
1012
let instance = null;
1113

@@ -55,6 +57,27 @@ describe('<Tippy />', () => {
5557
expect(instance.popper.querySelector('strong')).not.toBeNull();
5658
});
5759

60+
test('cleans up after unmounting in tests', async () => {
61+
render(
62+
<Tippy
63+
content="tooltip"
64+
trigger="click"
65+
// test will fail if animation is enabled
66+
animation={false}
67+
>
68+
<button />
69+
</Tippy>,
70+
);
71+
72+
// open up the tooltip
73+
screen.getByRole('button').click();
74+
expect(screen.getByText('tooltip')).toBeInTheDocument();
75+
76+
// close the tooltip
77+
screen.getByRole('button').click();
78+
await waitForElementToBeRemoved(() => screen.queryByText('tooltip'));
79+
});
80+
5881
test('props.className: single name is added to tooltip', () => {
5982
const className = 'hello';
6083

0 commit comments

Comments
 (0)