11import React , { RefObject } from 'react' ;
22import { Dimensions , Text , View , Platform } from 'react-native' ;
33
4- import {
5- fireEvent ,
6- render ,
7- waitForElementToBeRemoved ,
8- } from '@testing-library/react-native' ;
4+ import { fireEvent , render , act } from '@testing-library/react-native' ;
95
106import PaperProvider from '../../core/PaperProvider' ;
117import Tooltip from '../Tooltip/Tooltip' ;
@@ -116,21 +112,27 @@ describe('Tooltip', () => {
116112 } ) ;
117113
118114 describe ( 'pressOut' , ( ) => {
119- // eslint-disable-next-line jest/valid-title
120115 it ( 'hides the tooltip when the user stop pressing the component' , async ( ) => {
121116 const {
122- wrapper : { queryByText , getByText, findByText } ,
117+ wrapper : { getByText, findByText } ,
123118 } = setup ( { enterTouchDelay : 50 , leaveTouchDelay : 0 } ) ;
124119
125120 fireEvent ( getByText ( 'dummy component' ) , 'longPress' ) ;
126121
127- await findByText ( 'some tooltip text' ) ;
122+ act ( ( ) => {
123+ jest . runAllTimers ( ) ;
124+ } ) ;
125+
126+ const tooltip = await findByText ( 'some tooltip text' ) ;
127+ expect ( tooltip ) . toBeOnTheScreen ( ) ;
128128
129129 fireEvent ( getByText ( 'dummy component' ) , 'pressOut' ) ;
130130
131- await waitForElementToBeRemoved ( ( ) => getByText ( 'some tooltip text' ) ) ;
131+ act ( ( ) => {
132+ jest . runAllTimers ( ) ;
133+ } ) ;
132134
133- expect ( queryByText ( 'some tooltip text' ) ) . toBeNull ( ) ;
135+ expect ( tooltip ) . not . toBeOnTheScreen ( ) ;
134136 } ) ;
135137 } ) ;
136138
@@ -286,6 +288,10 @@ describe('Tooltip', () => {
286288
287289 fireEvent ( getByText ( 'dummy component' ) , 'hoverIn' ) ;
288290
291+ act ( ( ) => {
292+ jest . runAllTimers ( ) ;
293+ } ) ;
294+
289295 await findByText ( 'some tooltip text' ) ;
290296
291297 unmount ( ) ;
@@ -306,6 +312,11 @@ describe('Tooltip', () => {
306312 } = setup ( ) ;
307313
308314 fireEvent ( getByText ( 'dummy component' ) , 'hoverIn' ) ;
315+
316+ act ( ( ) => {
317+ jest . runAllTimers ( ) ;
318+ } ) ;
319+
309320 fireEvent ( getByText ( 'dummy component' ) , 'hoverOut' ) ;
310321 fireEvent ( getByText ( 'dummy component' ) , 'hoverIn' ) ;
311322
@@ -314,21 +325,27 @@ describe('Tooltip', () => {
314325 } ) ;
315326
316327 describe ( 'hoverOut' , ( ) => {
317- // eslint-disable-next-line jest/valid-title
318328 it ( 'hides the tooltip when the user stops hovering the component' , async ( ) => {
319329 const {
320330 wrapper : { queryByText, getByText, findByText } ,
321331 } = setup ( { enterTouchDelay : 50 , leaveTouchDelay : 0 } ) ;
322332
323333 fireEvent ( getByText ( 'dummy component' ) , 'hoverIn' ) ;
324334
325- await findByText ( 'some tooltip text' ) ;
335+ act ( ( ) => {
336+ jest . runAllTimers ( ) ;
337+ } ) ;
338+
339+ const tooltip = await findByText ( 'some tooltip text' ) ;
340+ expect ( tooltip ) . toBeOnTheScreen ( ) ;
326341
327342 fireEvent ( getByText ( 'dummy component' ) , 'hoverOut' ) ;
328343
329- await waitForElementToBeRemoved ( ( ) => getByText ( 'some tooltip text' ) ) ;
344+ act ( ( ) => {
345+ jest . runAllTimers ( ) ;
346+ } ) ;
330347
331- expect ( queryByText ( 'some tooltip text' ) ) . toBeNull ( ) ;
348+ expect ( queryByText ( 'some tooltip text' ) ) . not . toBeOnTheScreen ( ) ;
332349 } ) ;
333350 } ) ;
334351
@@ -355,6 +372,10 @@ describe('Tooltip', () => {
355372
356373 fireEvent ( getByText ( 'dummy component' ) , 'hoverIn' ) ;
357374
375+ act ( ( ) => {
376+ jest . runAllTimers ( ) ;
377+ } ) ;
378+
358379 fireEvent ( await findByText ( 'some tooltip text' ) , 'layout' , {
359380 nativeEvent : {
360381 layout : { width : TOOLTIP_WIDTH , height : TOOLTIP_HEIGHT } ,
@@ -379,6 +400,10 @@ describe('Tooltip', () => {
379400
380401 fireEvent ( getByText ( 'dummy component' ) , 'hoverIn' ) ;
381402
403+ act ( ( ) => {
404+ jest . runAllTimers ( ) ;
405+ } ) ;
406+
382407 fireEvent ( await findByText ( 'some tooltip text' ) , 'layout' , {
383408 nativeEvent : {
384409 layout : { width : TOOLTIP_WIDTH , height : TOOLTIP_HEIGHT } ,
@@ -403,6 +428,10 @@ describe('Tooltip', () => {
403428
404429 fireEvent ( getByText ( 'dummy component' ) , 'hoverIn' ) ;
405430
431+ act ( ( ) => {
432+ jest . runAllTimers ( ) ;
433+ } ) ;
434+
406435 fireEvent ( await findByText ( 'some tooltip text' ) , 'layout' , {
407436 nativeEvent : {
408437 layout : { width : TOOLTIP_WIDTH , height : TOOLTIP_HEIGHT } ,
@@ -427,6 +456,10 @@ describe('Tooltip', () => {
427456
428457 fireEvent ( getByText ( 'dummy component' ) , 'hoverIn' ) ;
429458
459+ act ( ( ) => {
460+ jest . runAllTimers ( ) ;
461+ } ) ;
462+
430463 fireEvent ( await findByText ( 'some tooltip text' ) , 'layout' , {
431464 nativeEvent : {
432465 layout : { width : TOOLTIP_WIDTH , height : TOOLTIP_HEIGHT } ,
0 commit comments