11/* eslint-disable max-classes-per-file */
22
3- import React , { StrictMode , createRef } from 'react' ;
4- import ReactDOM from 'react-dom' ;
53import { act , cleanup , fireEvent , render } from '@testing-library/react' ;
64import { spyElementPrototypes } from 'rc-util/lib/test/domHook' ;
5+ import React , { createRef , StrictMode } from 'react' ;
6+ import ReactDOM from 'react-dom' ;
77import Trigger from '../src' ;
88import { placementAlignMap } from './util' ;
99
@@ -480,15 +480,21 @@ describe('Trigger.Basic', () => {
480480 </ Trigger > ,
481481 ) ;
482482
483+ const width = 1128 ;
484+ const height = 903 ;
483485 let domSpy ;
486+ let rect = { } ;
484487
485488 beforeAll ( ( ) => {
486489 domSpy = spyElementPrototypes ( HTMLElement , {
487490 offsetWidth : {
488- get : ( ) => 1128 ,
491+ get : ( ) => width ,
489492 } ,
490493 offsetHeight : {
491- get : ( ) => 903 ,
494+ get : ( ) => height ,
495+ } ,
496+ getBoundingClientRect ( ) {
497+ return rect ;
492498 } ,
493499 } ) ;
494500 } ) ;
@@ -497,16 +503,19 @@ describe('Trigger.Basic', () => {
497503 domSpy . mockRestore ( ) ;
498504 } ) ;
499505
500- [ 'width' , 'height' , 'min-width' , 'min-height' ] . forEach ( ( prop ) => {
501- it ( prop , ( ) => {
502- const { container } = createTrigger ( prop ) ;
506+ [ null , { width, height } ] . forEach ( ( mockRect ) => {
507+ [ 'width' , 'height' , 'min-width' , 'min-height' ] . forEach ( ( prop ) => {
508+ it ( `${ mockRect ? 'offset' : 'getBoundingClientRect' } : ${ prop } ` , ( ) => {
509+ const { container } = createTrigger ( prop ) ;
510+ rect = mockRect || { } ;
503511
504- fireEvent . click ( container . querySelector ( '.target' ) ) ;
505- act ( ( ) => jest . runAllTimers ( ) ) ;
512+ fireEvent . click ( container . querySelector ( '.target' ) ) ;
513+ act ( ( ) => jest . runAllTimers ( ) ) ;
506514
507- expect (
508- document . querySelector ( '.rc-trigger-popup' ) . style ,
509- ) . toHaveProperty ( prop ) ;
515+ expect (
516+ document . querySelector ( '.rc-trigger-popup' ) . style ,
517+ ) . toHaveProperty ( prop ) ;
518+ } ) ;
510519 } ) ;
511520 } ) ;
512521 } ) ;
0 commit comments