@@ -510,13 +510,14 @@ describe('Trigger.Basic', () => {
510
510
} ) ;
511
511
512
512
describe ( 'stretch' , ( ) => {
513
- const createTrigger = ( stretch ) =>
513
+ const createTrigger = ( stretch , restProps ) =>
514
514
render (
515
515
< Trigger
516
516
action = { [ 'click' ] }
517
517
popupAlign = { placementAlignMap . left }
518
518
popup = { < strong className = "x-content" > tooltip2</ strong > }
519
519
stretch = { stretch }
520
+ { ...restProps }
520
521
>
521
522
< div className = "target" >
522
523
click me to show trigger
@@ -530,6 +531,7 @@ describe('Trigger.Basic', () => {
530
531
const height = 903 ;
531
532
let domSpy ;
532
533
let rect = { } ;
534
+ let rectCalled = false ;
533
535
534
536
beforeAll ( ( ) => {
535
537
domSpy = spyElementPrototypes ( HTMLElement , {
@@ -540,23 +542,45 @@ describe('Trigger.Basic', () => {
540
542
get : ( ) => height ,
541
543
} ,
542
544
getBoundingClientRect ( ) {
545
+ rectCalled = true ;
543
546
return rect ;
544
547
} ,
545
548
} ) ;
546
549
} ) ;
547
550
551
+ beforeEach ( ( ) => {
552
+ rectCalled = false ;
553
+ } ) ;
554
+
548
555
afterAll ( ( ) => {
549
556
domSpy . mockRestore ( ) ;
550
557
} ) ;
551
558
552
559
[ null , { width, height } ] . forEach ( ( mockRect ) => {
553
560
[ '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
+ } ) ;
556
569
rect = mockRect || { } ;
557
570
571
+ expect ( rectCalled ) . toBeFalsy ( ) ;
572
+ expect ( onPopupAlign ) . not . toHaveBeenCalled ( ) ;
573
+
574
+ // Click will trigger `onPrepare` which need measure target size
558
575
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 ( ) ;
560
584
561
585
expect (
562
586
document . querySelector ( '.rc-trigger-popup' ) . style ,
0 commit comments