@@ -3,31 +3,33 @@ import scrollTo from '@studiometa/js-toolkit/utils/scrollTo';
33import wait from '../__utils__/wait' ;
44
55describe ( 'The `scrollTo` function' , ( ) => {
6- const fn = jest . fn ( ( { top } ) => { window . pageYOffset = top ; } ) ;
6+ const fn = jest . fn ( ( { top } ) => {
7+ window . pageYOffset = top ;
8+ } ) ;
79 window . scrollTo = fn ;
810
9- const bodyHeightSpy = jest . spyOn ( document . body , 'offsetHeight ' , 'get' ) ;
10- bodyHeightSpy . mockImplementation ( ( ) => 10000 ) ;
11+ const scrollHeightSpy = jest . spyOn ( document . documentElement , 'scrollHeight ' , 'get' ) ;
12+ scrollHeightSpy . mockImplementation ( ( ) => 10000 ) ;
1113
1214 const element = document . createElement ( 'div' ) ;
1315 const elementSpy = jest . spyOn ( element , 'getBoundingClientRect' ) ;
1416 elementSpy . mockImplementation ( ( ) => ( {
15- top : 5000
16- } ) )
17+ top : 5000 ,
18+ } ) ) ;
1719
1820 document . body . appendChild ( element ) ;
1921
2022 afterAll ( ( ) => {
2123 delete window . scrollTo ;
22- bodyHeightSpy . mockRestore ( ) ;
24+ scrollHeightSpy . mockRestore ( ) ;
2325 elementSpy . mockRestore ( ) ;
2426 document . body . innerHTML = '' ;
2527 } ) ;
2628
2729 beforeEach ( ( ) => {
2830 fn . mockClear ( ) ;
2931 window . pageYOffset = 0 ;
30- } )
32+ } ) ;
3133
3234 it ( 'should scroll to a selector' , async ( ) => {
3335 expect ( fn ) . not . toHaveBeenCalled ( ) ;
@@ -49,10 +51,10 @@ describe('The `scrollTo` function', () => {
4951
5052 it ( 'should be limited to the maximum scroll height' , async ( ) => {
5153 elementSpy . mockImplementation ( ( ) => ( {
52- top : 11000
54+ top : 11000 ,
5355 } ) ) ;
5456 expect ( fn ) . not . toHaveBeenCalled ( ) ;
55- const maxScroll = document . body . offsetHeight - window . innerHeight ;
57+ const maxScroll = document . documentElement . scrollHeight - window . innerHeight ;
5658 await scrollTo ( element ) ;
5759 expect ( fn ) . toHaveBeenLastCalledWith ( { top : maxScroll } ) ;
5860 } ) ;
0 commit comments