@@ -5,13 +5,19 @@ import { spyElementPrototypes } from './utils/domHook';
55import List from '../src' ;
66import { createEvent , fireEvent , render } from '@testing-library/react' ;
77import { resetWarned } from 'rc-util/lib/warning' ;
8+ import { _rs as onLibResize } from 'rc-resize-observer/lib/utils/observerUtil' ;
9+ import '@testing-library/jest-dom' ;
810
911function genData ( count ) {
1012 return new Array ( count ) . fill ( null ) . map ( ( _ , index ) => ( { id : String ( index ) } ) ) ;
1113}
1214
1315describe ( 'List.Scroll' , ( ) => {
1416 let mockElement ;
17+ let boundingRect = {
18+ width : 100 ,
19+ height : 100 ,
20+ } ;
1521
1622 beforeAll ( ( ) => {
1723 mockElement = spyElementPrototypes ( HTMLElement , {
@@ -21,10 +27,7 @@ describe('List.Scroll', () => {
2127 clientHeight : {
2228 get : ( ) => 100 ,
2329 } ,
24- getBoundingClientRect : ( ) => ( {
25- width : 100 ,
26- height : 100 ,
27- } ) ,
30+ getBoundingClientRect : ( ) => boundingRect ,
2831 offsetParent : {
2932 get : ( ) => document . body ,
3033 } ,
@@ -36,6 +39,10 @@ describe('List.Scroll', () => {
3639 } ) ;
3740
3841 beforeEach ( ( ) => {
42+ boundingRect = {
43+ width : 100 ,
44+ height : 100 ,
45+ } ;
3946 jest . useFakeTimers ( ) ;
4047 } ) ;
4148
@@ -436,4 +443,34 @@ describe('List.Scroll', () => {
436443 ) . style . background ,
437444 ) . toEqual ( 'blue' ) ;
438445 } ) ;
446+
447+ it ( 'scrollbar size should correct' , async ( ) => {
448+ boundingRect = {
449+ width : 0 ,
450+ height : 0 ,
451+ } ;
452+
453+ const { container } = genList (
454+ {
455+ itemHeight : 20 ,
456+ height : 100 ,
457+ data : genData ( 100 ) ,
458+ } ,
459+ render ,
460+ ) ;
461+
462+ await act ( async ( ) => {
463+ onLibResize ( [
464+ {
465+ target : container . querySelector ( '.rc-virtual-list-holder' ) ,
466+ } ,
467+ ] ) ;
468+
469+ await Promise . resolve ( ) ;
470+ } ) ;
471+
472+ expect ( container . querySelector ( '.rc-virtual-list-scrollbar-thumb' ) ) . toHaveStyle ( {
473+ height : `10px` ,
474+ } ) ;
475+ } ) ;
439476} ) ;
0 commit comments