@@ -2368,3 +2368,91 @@ describe('Select.Basic', () => {
2368
2368
expect ( element [ 1 ] ) . toHaveClass ( 'rc-select-item-option-disabled' ) ;
2369
2369
} ) ;
2370
2370
} ) ;
2371
+
2372
+ describe ( 'Select.Deprecated APIs' , ( ) => {
2373
+ beforeAll ( ( ) => {
2374
+ jest . useFakeTimers ( ) ;
2375
+ } ) ;
2376
+
2377
+ afterAll ( ( ) => {
2378
+ jest . useRealTimers ( ) ;
2379
+ } ) ;
2380
+
2381
+ beforeEach ( ( ) => {
2382
+ resetWarned ( ) ;
2383
+ } ) ;
2384
+
2385
+ const deprecatedAPIs = {
2386
+ dropdownClassName : 'popupClassName' ,
2387
+ dropdownStyle : 'popupStyle' ,
2388
+ dropdownAlign : 'popupAlign' ,
2389
+ dropdownRender : 'popupRender' ,
2390
+ dropdownMatchSelectWidth : 'popupMatchSelectWidth' ,
2391
+ onDropdownVisibleChange : 'onPopupVisibleChange' ,
2392
+ } ;
2393
+
2394
+ Object . entries ( deprecatedAPIs ) . forEach ( ( [ deprecatedProp , newProp ] ) => {
2395
+ it ( `should warning if use deprecated API '${ deprecatedProp } '` , ( ) => {
2396
+ const errorSpy = jest . spyOn ( console , 'error' ) . mockImplementation ( ( ) => { } ) ;
2397
+
2398
+ const props = {
2399
+ [ deprecatedProp ] : deprecatedProp === 'dropdownRender' ? ( menu ) => menu : true ,
2400
+ } ;
2401
+
2402
+ render (
2403
+ < Select { ...props } >
2404
+ < Option value = "1" > 1</ Option >
2405
+ </ Select > ,
2406
+ ) ;
2407
+
2408
+ expect ( errorSpy ) . toHaveBeenCalledWith (
2409
+ `Warning: \`${ deprecatedProp } \` is deprecated. Please use \`${ newProp } \` instead.` ,
2410
+ ) ;
2411
+
2412
+ errorSpy . mockRestore ( ) ;
2413
+ } ) ;
2414
+ } ) ;
2415
+
2416
+ it ( 'should not warning if use new APIs' , ( ) => {
2417
+ const errorSpy = jest . spyOn ( console , 'error' ) . mockImplementation ( ( ) => { } ) ;
2418
+
2419
+ render (
2420
+ < Select
2421
+ popupClassName = "test"
2422
+ popupStyle = { { color : 'red' } }
2423
+ popupAlign = { { offset : [ 0 , 0 ] } }
2424
+ popupRender = { ( menu ) => menu }
2425
+ popupMatchSelectWidth = { 100 }
2426
+ onPopupVisibleChange = { ( ) => { } }
2427
+ >
2428
+ < Option value = "1" > 1</ Option >
2429
+ </ Select > ,
2430
+ ) ;
2431
+
2432
+ expect ( errorSpy ) . not . toHaveBeenCalled ( ) ;
2433
+ errorSpy . mockRestore ( ) ;
2434
+ } ) ;
2435
+
2436
+ it ( 'should work with both old and new APIs' , ( ) => {
2437
+ const errorSpy = jest . spyOn ( console , 'error' ) . mockImplementation ( ( ) => { } ) ;
2438
+
2439
+ const { container } = render (
2440
+ < Select dropdownMatchSelectWidth = { 100 } popupMatchSelectWidth = { 200 } >
2441
+ < Option value = "1" > 1</ Option >
2442
+ </ Select > ,
2443
+ ) ;
2444
+
2445
+ // Should use new API value
2446
+ toggleOpen ( container ) ;
2447
+ expect ( ( container . querySelector ( '.rc-select-dropdown' ) as HTMLElement ) . style . width ) . toBe (
2448
+ '200px' ,
2449
+ ) ;
2450
+
2451
+ // Should still show warning
2452
+ expect ( errorSpy ) . toHaveBeenCalledWith (
2453
+ `Warning: \`dropdownMatchSelectWidth\` is deprecated. Please use \`popupMatchSelectWidth\` instead.` ,
2454
+ ) ;
2455
+
2456
+ errorSpy . mockRestore ( ) ;
2457
+ } ) ;
2458
+ } ) ;
0 commit comments