@@ -75,6 +75,8 @@ describe("AutoSizer", () => {
7575 beforeEach ( ( ) => {
7676 // @ts -ignore
7777 global . IS_REACT_ACT_ENVIRONMENT = true ;
78+
79+ jest . resetAllMocks ( ) ;
7880 } ) ;
7981
8082 function renderHelper (
@@ -353,6 +355,81 @@ describe("AutoSizer", () => {
353355 expect ( ChildComponent ) . toHaveBeenCalledTimes ( 1 ) ;
354356 expect ( onResize ) . toHaveBeenCalledTimes ( 2 ) ;
355357 } ) ;
358+
359+ it ( "should warn if deprecated scaledHeight accessor is used" , async ( ) => {
360+ const consoleWarnSpy = jest
361+ . spyOn ( console , "warn" )
362+ . mockImplementation ( ( ) => { } ) ;
363+
364+ // Destructure syntax should warn too
365+ const onResize = jest . fn ( ( { height, scaledHeight } ) => {
366+ expect ( consoleWarnSpy ) . toHaveBeenCalledTimes ( 1 ) ;
367+ expect ( consoleWarnSpy ) . toHaveBeenCalledWith (
368+ "scaledWidth and scaledHeight parameters have been deprecated; use width and height instead"
369+ ) ;
370+
371+ expect ( height ) . toBe ( 100.5 ) ;
372+ expect ( scaledHeight ) . toBe ( 100.5 ) ;
373+ } ) ;
374+
375+ const ChildComponent = jest
376+ . fn ( )
377+ . mockImplementation ( DefaultChildComponent ) ;
378+
379+ renderHelper (
380+ {
381+ ChildComponent,
382+ height : 100.5 ,
383+ width : 200.5 ,
384+ } ,
385+ {
386+ disableHeight : true ,
387+ onResize,
388+ }
389+ ) ;
390+
391+ expect ( onResize ) . toHaveBeenCalledTimes ( 1 ) ;
392+ } ) ;
393+
394+ it ( "should warn if deprecated scaledWidth accessor is used" , async ( ) => {
395+ const consoleWarnSpy = jest
396+ . spyOn ( console , "warn" )
397+ . mockImplementation ( ( ) => { } ) ;
398+
399+ const onResize = jest . fn ( ( params ) => {
400+ expect ( params . width ) . toBe ( 200.5 ) ;
401+ expect ( consoleWarnSpy ) . not . toHaveBeenCalled ( ) ;
402+
403+ // Should be called when first accessed
404+ expect ( params . scaledWidth ) . toBe ( 200.5 ) ;
405+ expect ( consoleWarnSpy ) . toHaveBeenCalledTimes ( 1 ) ;
406+ expect ( consoleWarnSpy ) . toHaveBeenCalledWith (
407+ "scaledWidth and scaledHeight parameters have been deprecated; use width and height instead"
408+ ) ;
409+
410+ // Should not be called again
411+ expect ( params . scaledWidth ) . toBe ( 200.5 ) ;
412+ expect ( consoleWarnSpy ) . toHaveBeenCalledTimes ( 1 ) ;
413+ } ) ;
414+
415+ const ChildComponent = jest
416+ . fn ( )
417+ . mockImplementation ( DefaultChildComponent ) ;
418+
419+ renderHelper (
420+ {
421+ ChildComponent,
422+ height : 100.5 ,
423+ width : 200.5 ,
424+ } ,
425+ {
426+ disableHeight : true ,
427+ onResize,
428+ }
429+ ) ;
430+
431+ expect ( onResize ) . toHaveBeenCalledTimes ( 1 ) ;
432+ } ) ;
356433 } ) ;
357434
358435 describe ( "HTML attributes" , ( ) => {
0 commit comments