@@ -6,7 +6,8 @@ import React from 'react';
66import { act } from 'react-dom/test-utils' ;
77import classNames from 'classnames' ;
88import { mount } from './wrapper' ;
9- import RefCSSMotion , { genCSSMotion , CSSMotionProps } from '../src/CSSMotion' ;
9+ import type { CSSMotionProps } from '../src/CSSMotion' ;
10+ import RefCSSMotion , { genCSSMotion } from '../src/CSSMotion' ;
1011
1112describe ( 'CSSMotion' , ( ) => {
1213 const CSSMotion = genCSSMotion ( {
@@ -267,7 +268,7 @@ describe('CSSMotion', () => {
267268
268269 test (
269270 'without ref' ,
270- React . forwardRef ( ( props ) => < div { ...props } /> ) ,
271+ React . forwardRef ( props => < div { ...props } /> ) ,
271272 ) ;
272273
273274 test (
@@ -552,7 +553,7 @@ describe('CSSMotion', () => {
552553 let lockResolve : Function ;
553554 const onAppearPrepare = jest . fn (
554555 ( ) =>
555- new Promise ( ( resolve ) => {
556+ new Promise ( resolve => {
556557 lockResolve = resolve ;
557558 } ) ,
558559 ) ;
@@ -606,4 +607,46 @@ describe('CSSMotion', () => {
606607 wrapper . setProps ( { forceRender : false } ) ;
607608 expect ( wrapper . find ( '.motion-box' ) ) . toHaveLength ( 0 ) ;
608609 } ) ;
610+
611+ it ( 'render null on first when removeOnLeave is false' , ( ) => {
612+ const wrapper = mount (
613+ < CSSMotion
614+ motionName = "bamboo"
615+ removeOnLeave = { false }
616+ leavedClassName = "removed"
617+ visible = { false }
618+ >
619+ { ( { style, className } ) => (
620+ < div style = { style } className = { classNames ( 'motion-box' , className ) } />
621+ ) }
622+ </ CSSMotion > ,
623+ ) ;
624+
625+ expect ( wrapper . find ( '.motion-box' ) ) . toHaveLength ( 0 ) ;
626+
627+ // Visible
628+ wrapper . setProps ( { visible : true } ) ;
629+ act ( ( ) => {
630+ jest . runAllTimers ( ) ;
631+ wrapper . update ( ) ;
632+ } ) ;
633+ expect ( wrapper . find ( '.motion-box' ) ) . toHaveLength ( 1 ) ;
634+
635+ // Hide again
636+ wrapper . setProps ( { visible : false } ) ;
637+ act ( ( ) => {
638+ jest . runAllTimers ( ) ;
639+
640+ const transitionEndEvent = new Event ( 'transitionend' ) ;
641+ ( ( wrapper
642+ . find ( '.motion-box' )
643+ . instance ( ) as any ) as HTMLElement ) . dispatchEvent ( transitionEndEvent ) ;
644+
645+ jest . runAllTimers ( ) ;
646+
647+ wrapper . update ( ) ;
648+ } ) ;
649+ expect ( wrapper . find ( '.motion-box' ) ) . toHaveLength ( 1 ) ;
650+ expect ( wrapper . find ( '.motion-box' ) . hasClass ( 'removed' ) ) . toBeTruthy ( ) ;
651+ } ) ;
609652} ) ;
0 commit comments