This repository was archived by the owner on Nov 9, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +264
-43
lines changed Expand file tree Collapse file tree 4 files changed +264
-43
lines changed Original file line number Diff line number Diff 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} ;
Original file line number Diff line number Diff line change 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"
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" ,
Original file line number Diff line number Diff line change 11import React , { useRef , useState } from 'react' ;
22import 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
59jest . useFakeTimers ( ) ;
610
7- afterEach ( cleanup ) ;
8-
911describe ( '<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
You can’t perform that action at this time.
0 commit comments