11import React from 'react' ;
2- import { render } from './utils' ;
2+ import { render , waitFor } from './utils' ;
33
44import CSSTransition from '../src/CSSTransition' ;
55import TransitionGroup from '../src/TransitionGroup' ;
@@ -36,8 +36,9 @@ describe('CSSTransition', () => {
3636 } ) ;
3737
3838 describe ( 'entering' , ( ) => {
39- it ( 'should apply classes at each transition state' , ( done ) => {
39+ it ( 'should apply classes at each transition state' , async ( ) => {
4040 let count = 0 ;
41+ let done = false ;
4142 const nodeRef = React . createRef ( ) ;
4243 const { setProps } = render (
4344 < CSSTransition nodeRef = { nodeRef } timeout = { 10 } classNames = "test" >
@@ -63,12 +64,16 @@ describe('CSSTransition', () => {
6364 onEntered ( ) {
6465 expect ( nodeRef . current . className ) . toEqual ( 'test-enter-done' ) ;
6566 expect ( count ) . toEqual ( 2 ) ;
66- done ( ) ;
67+ done = true ;
6768 } ,
6869 } ) ;
70+
71+ await waitFor ( ( ) => {
72+ expect ( done ) . toBe ( true ) ;
73+ } ) ;
6974 } ) ;
7075
71- it ( 'should apply custom classNames names' , ( done ) => {
76+ it ( 'should apply custom classNames names' , async ( ) => {
7277 let count = 0 ;
7378 const nodeRef = React . createRef ( ) ;
7479 const { setProps } = render (
@@ -102,15 +107,17 @@ describe('CSSTransition', () => {
102107
103108 onEntered ( ) {
104109 expect ( nodeRef . current . className ) . toEqual ( 'custom-super-done' ) ;
105- expect ( count ) . toEqual ( 2 ) ;
106- done ( ) ;
107110 } ,
108111 } ) ;
112+
113+ await waitFor ( ( ) => {
114+ expect ( count ) . toEqual ( 2 ) ;
115+ } ) ;
109116 } ) ;
110117 } ) ;
111118
112119 describe ( 'appearing' , ( ) => {
113- it ( 'should apply appear classes at each transition state' , ( done ) => {
120+ it ( 'should apply appear classes at each transition state' , async ( ) => {
114121 let count = 0 ;
115122 const nodeRef = React . createRef ( ) ;
116123 render (
@@ -137,17 +144,21 @@ describe('CSSTransition', () => {
137144 expect ( nodeRef . current . className ) . toEqual (
138145 'appear-test-appear-done appear-test-enter-done'
139146 ) ;
140- expect ( count ) . toEqual ( 2 ) ;
141- done ( ) ;
142147 } }
143148 >
144149 < div ref = { nodeRef } />
145150 </ CSSTransition >
146151 ) ;
152+
153+ await waitFor ( ( ) => {
154+ expect ( count ) . toEqual ( 2 ) ;
155+ } ) ;
147156 } ) ;
148157
149- it ( 'should lose the "*-appear-done" class after leaving and entering again' , ( done ) => {
158+ it ( 'should lose the "*-appear-done" class after leaving and entering again' , async ( ) => {
150159 const nodeRef = React . createRef ( ) ;
160+ let entered = false ;
161+ let exited = false ;
151162 const { setProps } = render (
152163 < CSSTransition
153164 timeout = { 10 }
@@ -156,31 +167,45 @@ describe('CSSTransition', () => {
156167 in = { true }
157168 appear = { true }
158169 onEntered = { ( ) => {
159- setProps ( {
160- in : false ,
161- onEntered : ( ) => { } ,
162- onExited : ( ) => {
163- expect ( nodeRef . current . className ) . toBe ( 'appear-test-exit-done' ) ;
164- setProps ( {
165- in : true ,
166- onEntered : ( ) => {
167- expect ( nodeRef . current . className ) . toBe (
168- 'appear-test-enter-done'
169- ) ;
170- done ( ) ;
171- } ,
172- } ) ;
173- } ,
174- } ) ;
170+ entered = true ;
175171 } }
176172 >
177173 < div ref = { nodeRef } />
178174 </ CSSTransition >
179175 ) ;
176+
177+ await waitFor ( ( ) => {
178+ expect ( entered ) . toEqual ( true ) ;
179+ } ) ;
180+ setProps ( {
181+ in : false ,
182+ onEntered : ( ) => { } ,
183+ onExited : ( ) => {
184+ exited = true ;
185+ } ,
186+ } ) ;
187+
188+ await waitFor ( ( ) => {
189+ expect ( exited ) . toEqual ( true ) ;
190+ } ) ;
191+ expect ( nodeRef . current . className ) . toBe ( 'appear-test-exit-done' ) ;
192+ entered = false ;
193+ setProps ( {
194+ in : true ,
195+ onEntered : ( ) => {
196+ entered = true ;
197+ } ,
198+ } ) ;
199+
200+ await waitFor ( ( ) => {
201+ expect ( entered ) . toEqual ( true ) ;
202+ } ) ;
203+ expect ( nodeRef . current . className ) . toBe ( 'appear-test-enter-done' ) ;
180204 } ) ;
181205
182- it ( 'should not add undefined when appearDone is not defined' , ( done ) => {
206+ it ( 'should not add undefined when appearDone is not defined' , async ( ) => {
183207 const nodeRef = React . createRef ( ) ;
208+ let done = false ;
184209 render (
185210 < CSSTransition
186211 timeout = { 10 }
@@ -195,15 +220,19 @@ describe('CSSTransition', () => {
195220 onEntered = { ( isAppearing ) => {
196221 expect ( isAppearing ) . toEqual ( true ) ;
197222 expect ( nodeRef . current . className ) . toEqual ( '' ) ;
198- done ( ) ;
223+ done = true ;
199224 } }
200225 >
201226 < div ref = { nodeRef } />
202227 </ CSSTransition >
203228 ) ;
229+
230+ await waitFor ( ( ) => {
231+ expect ( done ) . toEqual ( true ) ;
232+ } ) ;
204233 } ) ;
205234
206- it ( 'should not be appearing in normal enter mode' , ( done ) => {
235+ it ( 'should not be appearing in normal enter mode' , async ( ) => {
207236 let count = 0 ;
208237 const nodeRef = React . createRef ( ) ;
209238 render (
@@ -237,10 +266,12 @@ describe('CSSTransition', () => {
237266 expect ( nodeRef . current . className ) . toEqual (
238267 'not-appear-test-enter-done'
239268 ) ;
240- expect ( count ) . toEqual ( 2 ) ;
241- done ( ) ;
242269 } ,
243270 } ) ;
271+
272+ await waitFor ( ( ) => {
273+ expect ( count ) . toEqual ( 2 ) ;
274+ } ) ;
244275 } ) ;
245276
246277 it ( 'should not enter the transition states when appear=false' , ( ) => {
@@ -269,7 +300,7 @@ describe('CSSTransition', () => {
269300 } ) ;
270301
271302 describe ( 'exiting' , ( ) => {
272- it ( 'should apply classes at each transition state' , ( done ) => {
303+ it ( 'should apply classes at each transition state' , async ( ) => {
273304 let count = 0 ;
274305 const nodeRef = React . createRef ( ) ;
275306 const { setProps } = render (
@@ -295,13 +326,15 @@ describe('CSSTransition', () => {
295326
296327 onExited ( ) {
297328 expect ( nodeRef . current . className ) . toEqual ( 'test-exit-done' ) ;
298- expect ( count ) . toEqual ( 2 ) ;
299- done ( ) ;
300329 } ,
301330 } ) ;
331+
332+ await waitFor ( ( ) => {
333+ expect ( count ) . toEqual ( 2 ) ;
334+ } ) ;
302335 } ) ;
303336
304- it ( 'should apply custom classNames names' , ( done ) => {
337+ it ( 'should apply custom classNames names' , async ( ) => {
305338 let count = 0 ;
306339 const nodeRef = React . createRef ( ) ;
307340 const { setProps } = render (
@@ -336,13 +369,15 @@ describe('CSSTransition', () => {
336369
337370 onExited ( ) {
338371 expect ( nodeRef . current . className ) . toEqual ( 'custom-super-done' ) ;
339- expect ( count ) . toEqual ( 2 ) ;
340- done ( ) ;
341372 } ,
342373 } ) ;
374+
375+ await waitFor ( ( ) => {
376+ expect ( count ) . toEqual ( 2 ) ;
377+ } ) ;
343378 } ) ;
344379
345- it ( 'should support empty prefix' , ( done ) => {
380+ it ( 'should support empty prefix' , async ( ) => {
346381 let count = 0 ;
347382
348383 const nodeRef = React . createRef ( ) ;
@@ -367,10 +402,12 @@ describe('CSSTransition', () => {
367402
368403 onExited ( ) {
369404 expect ( nodeRef . current . className ) . toEqual ( 'exit-done' ) ;
370- expect ( count ) . toEqual ( 2 ) ;
371- done ( ) ;
372405 } ,
373406 } ) ;
407+
408+ await waitFor ( ( ) => {
409+ expect ( count ) . toEqual ( 2 ) ;
410+ } ) ;
374411 } ) ;
375412 } ) ;
376413
@@ -412,20 +449,7 @@ describe('CSSTransition', () => {
412449 < Test direction = "down" text = "foo" nodeRef = { nodeRef . foo } />
413450 ) ;
414451
415- const rerender = ( getProps ) =>
416- new Promise ( ( resolve ) =>
417- setProps ( {
418- onEnter : undefined ,
419- onEntering : undefined ,
420- onEntered : undefined ,
421- onExit : undefined ,
422- onExiting : undefined ,
423- onExited : undefined ,
424- ...getProps ( resolve ) ,
425- } )
426- ) ;
427-
428- await rerender ( ( resolve ) => ( {
452+ setProps ( {
429453 direction : 'up' ,
430454 text : 'bar' ,
431455 nodeRef : nodeRef . bar ,
@@ -439,11 +463,14 @@ describe('CSSTransition', () => {
439463 expect ( nodeRef . bar . current . className ) . toEqual (
440464 'up-enter up-enter-active'
441465 ) ;
442- resolve ( ) ;
443466 } ,
444- } ) ) ;
467+ } ) ;
468+
469+ await waitFor ( ( ) => {
470+ expect ( count ) . toEqual ( 2 ) ;
471+ } ) ;
445472
446- await rerender ( ( resolve ) => ( {
473+ setProps ( {
447474 direction : 'down' ,
448475 text : 'foo' ,
449476 nodeRef : nodeRef . foo ,
@@ -457,11 +484,12 @@ describe('CSSTransition', () => {
457484 onEntered ( ) {
458485 count ++ ;
459486 expect ( nodeRef . foo . current . className ) . toEqual ( 'down-enter-done' ) ;
460- resolve ( ) ;
461487 } ,
462- } ) ) ;
488+ } ) ;
463489
464- expect ( count ) . toEqual ( 4 ) ;
490+ await waitFor ( ( ) => {
491+ expect ( count ) . toEqual ( 4 ) ;
492+ } ) ;
465493 } ) ;
466494 } ) ;
467495} ) ;
0 commit comments