@@ -5,13 +5,19 @@ import { spyElementPrototypes } from './utils/domHook';
5
5
import List from '../src' ;
6
6
import { createEvent , fireEvent , render } from '@testing-library/react' ;
7
7
import { resetWarned } from 'rc-util/lib/warning' ;
8
+ import { _rs as onLibResize } from 'rc-resize-observer/lib/utils/observerUtil' ;
9
+ import '@testing-library/jest-dom' ;
8
10
9
11
function genData ( count ) {
10
12
return new Array ( count ) . fill ( null ) . map ( ( _ , index ) => ( { id : String ( index ) } ) ) ;
11
13
}
12
14
13
15
describe ( 'List.Scroll' , ( ) => {
14
16
let mockElement ;
17
+ let boundingRect = {
18
+ width : 100 ,
19
+ height : 100 ,
20
+ } ;
15
21
16
22
beforeAll ( ( ) => {
17
23
mockElement = spyElementPrototypes ( HTMLElement , {
@@ -21,10 +27,7 @@ describe('List.Scroll', () => {
21
27
clientHeight : {
22
28
get : ( ) => 100 ,
23
29
} ,
24
- getBoundingClientRect : ( ) => ( {
25
- width : 100 ,
26
- height : 100 ,
27
- } ) ,
30
+ getBoundingClientRect : ( ) => boundingRect ,
28
31
offsetParent : {
29
32
get : ( ) => document . body ,
30
33
} ,
@@ -36,6 +39,10 @@ describe('List.Scroll', () => {
36
39
} ) ;
37
40
38
41
beforeEach ( ( ) => {
42
+ boundingRect = {
43
+ width : 100 ,
44
+ height : 100 ,
45
+ } ;
39
46
jest . useFakeTimers ( ) ;
40
47
} ) ;
41
48
@@ -436,4 +443,34 @@ describe('List.Scroll', () => {
436
443
) . style . background ,
437
444
) . toEqual ( 'blue' ) ;
438
445
} ) ;
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
+ } ) ;
439
476
} ) ;
0 commit comments