@@ -4,10 +4,10 @@ import {
44 WIDTH_UNIT ,
55} from "../constants" ;
66
7+ jest . mock ( './getContainerDimensions' ) ;
8+
79const container = {
810 style : { } ,
9- clientWidth : 99 ,
10- clientHeight : 100 ,
1111 querySelectorAll : ( ) => [ containerElement ] ,
1212} ;
1313
@@ -76,9 +76,18 @@ const config = {
7676 ] ,
7777} ;
7878
79+ beforeEach ( ( ) => {
80+ require ( './getContainerDimensions' ) . default . mockClear ( ) ;
81+ } ) ;
82+
7983test ( 'The container and its elements should be properly adjusted with the defaults' , ( ) => {
84+ const getContainerDimensionsMock = require ( './getContainerDimensions' ) . default . mockImplementation ( ( ) => {
85+ return { width : 99 , height : 100 } ;
86+ } ) ;
87+
8088 adjustContainer ( container , config ) ;
8189
90+ expect ( getContainerDimensionsMock ) . toHaveBeenCalledTimes ( 1 ) ;
8291 expect ( container . style ) . toEqual ( {
8392 borderWidth : 'calc(10px + 9.9px)' ,
8493 } ) ;
@@ -92,10 +101,13 @@ test('The container and its elements should be properly adjusted with the defaul
92101
93102describe ( 'query styles should be applied, then removed when conditions no longer apply' , ( ) => {
94103 test ( 'Apply query styles with width >= 100' , ( ) => {
95- container . clientWidth = 100 ;
104+ const getContainerDimensionsMock = require ( './getContainerDimensions' ) . default . mockImplementation ( ( ) => {
105+ return { width : 100 , height : 100 } ;
106+ } ) ;
96107
97108 adjustContainer ( container , config ) ;
98109
110+ expect ( getContainerDimensionsMock ) . toHaveBeenCalledTimes ( 1 ) ;
99111 expect ( container . style ) . toEqual ( {
100112 borderWidth : 'calc(20px + 20px)' ,
101113 } ) ;
@@ -108,10 +120,13 @@ describe('query styles should be applied, then removed when conditions no longer
108120 } ) ;
109121
110122 test ( 'Apply query styles with height >= 200' , ( ) => {
111- container . clientHeight = 200 ;
123+ const getContainerDimensionsMock = require ( './getContainerDimensions' ) . default . mockImplementation ( ( ) => {
124+ return { width : 100 , height : 200 } ;
125+ } ) ;
112126
113127 adjustContainer ( container , config ) ;
114128
129+ expect ( getContainerDimensionsMock ) . toHaveBeenCalledTimes ( 1 ) ;
115130 expect ( container . style ) . toEqual ( {
116131 borderWidth : 'calc(40px + 20px)' ,
117132 } ) ;
@@ -124,11 +139,13 @@ describe('query styles should be applied, then removed when conditions no longer
124139 } ) ;
125140
126141 test ( 'Remove all query styles, resetting back to the defaults' , ( ) => {
127- container . clientWidth = 99 ;
128- container . clientHeight = 99 ;
142+ const getContainerDimensionsMock = require ( './getContainerDimensions' ) . default . mockImplementation ( ( ) => {
143+ return { width : 99 , height : 99 } ;
144+ } ) ;
129145
130146 adjustContainer ( container , config ) ;
131147
148+ expect ( getContainerDimensionsMock ) . toHaveBeenCalledTimes ( 1 ) ;
132149 expect ( container . style ) . toEqual ( {
133150 borderWidth : 'calc(9.9px + 9.9px)' ,
134151 } ) ;
@@ -140,3 +157,11 @@ describe('query styles should be applied, then removed when conditions no longer
140157 } ) ;
141158 } ) ;
142159} ) ;
160+
161+ test ( "shouldn't adjust if the configuration is null (invalid)" , ( ) => {
162+ const getContainerDimensionsMock = require ( './getContainerDimensions' ) . default . mockImplementation ( ( ) => { console . log ( 'called' ) } ) ;
163+
164+ adjustContainer ( container ) ;
165+
166+ expect ( getContainerDimensionsMock ) . toHaveBeenCalledTimes ( 0 ) ;
167+ } ) ;
0 commit comments