@@ -510,13 +510,14 @@ describe('Trigger.Basic', () => {
510510 } ) ;
511511
512512 describe ( 'stretch' , ( ) => {
513- const createTrigger = ( stretch ) =>
513+ const createTrigger = ( stretch , restProps ) =>
514514 render (
515515 < Trigger
516516 action = { [ 'click' ] }
517517 popupAlign = { placementAlignMap . left }
518518 popup = { < strong className = "x-content" > tooltip2</ strong > }
519519 stretch = { stretch }
520+ { ...restProps }
520521 >
521522 < div className = "target" >
522523 click me to show trigger
@@ -530,6 +531,7 @@ describe('Trigger.Basic', () => {
530531 const height = 903 ;
531532 let domSpy ;
532533 let rect = { } ;
534+ let rectCalled = false ;
533535
534536 beforeAll ( ( ) => {
535537 domSpy = spyElementPrototypes ( HTMLElement , {
@@ -540,23 +542,45 @@ describe('Trigger.Basic', () => {
540542 get : ( ) => height ,
541543 } ,
542544 getBoundingClientRect ( ) {
545+ rectCalled = true ;
543546 return rect ;
544547 } ,
545548 } ) ;
546549 } ) ;
547550
551+ beforeEach ( ( ) => {
552+ rectCalled = false ;
553+ } ) ;
554+
548555 afterAll ( ( ) => {
549556 domSpy . mockRestore ( ) ;
550557 } ) ;
551558
552559 [ null , { width, height } ] . forEach ( ( mockRect ) => {
553560 [ 'width' , 'height' , 'min-width' , 'min-height' ] . forEach ( ( prop ) => {
554- it ( `${ mockRect ? 'offset' : 'getBoundingClientRect' } : ${ prop } ` , ( ) => {
555- const { container } = createTrigger ( prop ) ;
561+ it ( `${
562+ mockRect ? 'offset' : 'getBoundingClientRect'
563+ } : ${ prop } `, async ( ) => {
564+ const onPopupAlign = jest . fn ( ) ;
565+
566+ const { container } = createTrigger ( prop , {
567+ onPopupAlign,
568+ } ) ;
556569 rect = mockRect || { } ;
557570
571+ expect ( rectCalled ) . toBeFalsy ( ) ;
572+ expect ( onPopupAlign ) . not . toHaveBeenCalled ( ) ;
573+
574+ // Click will trigger `onPrepare` which need measure target size
558575 fireEvent . click ( container . querySelector ( '.target' ) ) ;
559- act ( ( ) => jest . runAllTimers ( ) ) ;
576+ expect ( rectCalled ) . toBeTruthy ( ) ;
577+
578+ // Flush for motion
579+ await act ( async ( ) => {
580+ jest . advanceTimersByTime ( 100 ) ;
581+ await Promise . resolve ( ) ;
582+ } ) ;
583+ expect ( onPopupAlign ) . toHaveBeenCalled ( ) ;
560584
561585 expect (
562586 document . querySelector ( '.rc-trigger-popup' ) . style ,
0 commit comments