@@ -99,11 +99,13 @@ const setShowError = jest.fn();
99
99
const setWindowTopOffset = jest . fn ( ) ;
100
100
101
101
const mockState = ( state ) => {
102
- const { iframeHeight, hasLoaded, showError, windowTopOffset } = state ;
103
- if ( 'iframeHeight' in state ) jest . spyOn ( iframeBehaviorState , 'iframeHeight' ) . mockImplementation ( ( ) => [ iframeHeight , setIframeHeight ] ) ;
104
- if ( 'hasLoaded' in state ) jest . spyOn ( iframeBehaviorState , 'hasLoaded' ) . mockImplementation ( ( ) => [ hasLoaded , setHasLoaded ] ) ;
105
- if ( 'showError' in state ) jest . spyOn ( iframeBehaviorState , 'showError' ) . mockImplementation ( ( ) => [ showError , setShowError ] ) ;
106
- if ( 'windowTopOffset' in state ) jest . spyOn ( iframeBehaviorState , 'windowTopOffset' ) . mockImplementation ( ( ) => [ windowTopOffset , setWindowTopOffset ] ) ;
102
+ const {
103
+ iframeHeight, hasLoaded, showError, windowTopOffset,
104
+ } = state ;
105
+ if ( 'iframeHeight' in state ) { jest . spyOn ( iframeBehaviorState , 'iframeHeight' ) . mockImplementation ( ( ) => [ iframeHeight , setIframeHeight ] ) ; }
106
+ if ( 'hasLoaded' in state ) { jest . spyOn ( iframeBehaviorState , 'hasLoaded' ) . mockImplementation ( ( ) => [ hasLoaded , setHasLoaded ] ) ; }
107
+ if ( 'showError' in state ) { jest . spyOn ( iframeBehaviorState , 'showError' ) . mockImplementation ( ( ) => [ showError , setShowError ] ) ; }
108
+ if ( 'windowTopOffset' in state ) { jest . spyOn ( iframeBehaviorState , 'windowTopOffset' ) . mockImplementation ( ( ) => [ windowTopOffset , setWindowTopOffset ] ) ; }
107
109
} ;
108
110
109
111
describe ( 'useIFrameBehavior hook' , ( ) => {
@@ -165,7 +167,7 @@ describe('useIFrameBehavior hook', () => {
165
167
] ) ;
166
168
} ) ;
167
169
describe ( 'resize message' , ( ) => {
168
- const height = 23 ;
170
+ const customHeight = 23 ;
169
171
const resizeMessage = ( height = 23 ) => ( {
170
172
data : { type : messageTypes . resize , payload : { height } } ,
171
173
} ) ;
@@ -182,9 +184,9 @@ describe('useIFrameBehavior hook', () => {
182
184
mockState ( { ...defaultStateVals , hasLoaded : true } ) ;
183
185
renderHook ( ( ) => useIFrameBehavior ( props ) ) ;
184
186
const { cb } = useEventListener . mock . calls [ 0 ] [ 1 ] ;
185
- cb ( resizeMessage ( height ) ) ;
187
+ cb ( resizeMessage ( customHeight ) ) ;
186
188
expect ( setIframeHeight ) . toHaveBeenCalledWith ( 0 ) ;
187
- expect ( setIframeHeight ) . toHaveBeenCalledWith ( height ) ;
189
+ expect ( setIframeHeight ) . toHaveBeenCalledWith ( customHeight ) ;
188
190
} ) ;
189
191
} ) ;
190
192
describe ( 'payload height is 0' , ( ) => {
@@ -194,7 +196,7 @@ describe('useIFrameBehavior hook', () => {
194
196
const { cb } = useEventListener . mock . calls [ 0 ] [ 1 ] ;
195
197
cb ( resizeMessage ( 0 ) ) ;
196
198
expect ( setIframeHeight ) . toHaveBeenCalledWith ( 0 ) ;
197
- expect ( setIframeHeight ) . not . toHaveBeenCalledWith ( height ) ;
199
+ expect ( setIframeHeight ) . not . toHaveBeenCalledWith ( customHeight ) ;
198
200
} ) ;
199
201
} ) ;
200
202
describe ( 'payload is present but uninitialized' , ( ) => {
@@ -277,7 +279,7 @@ describe('useIFrameBehavior hook', () => {
277
279
describe ( 'visibility tracking' , ( ) => {
278
280
it ( 'sets up visibility tracking after iframe has loaded' , ( ) => {
279
281
mockState ( { ...defaultStateVals , hasLoaded : true } ) ;
280
-
282
+
281
283
renderHook ( ( ) => useIFrameBehavior ( props ) ) ;
282
284
283
285
expect ( global . window . addEventListener ) . toHaveBeenCalledTimes ( 2 ) ;
0 commit comments