This repository was archived by the owner on Nov 9, 2024. It is now read-only.
File tree 4 files changed +264
-43
lines changed
4 files changed +264
-43
lines changed Original file line number Diff line number Diff line change @@ -4,4 +4,12 @@ module.exports = {
4
4
'@babel/react' ,
5
5
] ,
6
6
plugins : [ 'annotate-pure-calls' ] ,
7
+ env : {
8
+ test : {
9
+ presets : [
10
+ [ '@babel/env' , { targets : { node : 'current' } } ] ,
11
+ '@babel/react' ,
12
+ ]
13
+ }
14
+ }
7
15
} ;
Original file line number Diff line number Diff line change 29
29
],
30
30
"jest" : {
31
31
"setupFilesAfterEnv" : [
32
- " <rootDir>test/setup.js"
32
+ " <rootDir>test/setup.js" ,
33
+ " @testing-library/jest-dom/extend-expect"
33
34
],
34
35
"coveragePathIgnorePatterns" : [
35
36
" test/setup.js"
61
62
"@babel/core" : " ^7.8.7" ,
62
63
"@babel/preset-env" : " ^7.8.7" ,
63
64
"@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" ,
65
67
"@types/react" : " ^16.8.2" ,
66
68
"babel-eslint" : " ^10.0.1" ,
67
69
"babel-jest" : " ^25.1.0" ,
Original file line number Diff line number Diff line change 1
1
import React , { useRef , useState } from 'react' ;
2
2
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' ;
4
8
5
9
jest . useFakeTimers ( ) ;
6
10
7
- afterEach ( cleanup ) ;
8
-
9
11
describe ( '<Tippy />' , ( ) => {
10
12
let instance = null ;
11
13
@@ -55,6 +57,27 @@ describe('<Tippy />', () => {
55
57
expect ( instance . popper . querySelector ( 'strong' ) ) . not . toBeNull ( ) ;
56
58
} ) ;
57
59
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
+
58
81
test ( 'props.className: single name is added to tooltip' , ( ) => {
59
82
const className = 'hello' ;
60
83
You can’t perform that action at this time.
0 commit comments