@@ -18,7 +18,8 @@ describe('LazyLoadImage', function() {
1818 beforeLoad = ( ) => null ,
1919 placeholder = null ,
2020 scrollPosition = { x : 0 , y : 0 } ,
21- style = { }
21+ style = { } ,
22+ visibleByDefault = false
2223 } = { } ) {
2324 return mount (
2425 < LazyLoadImage
@@ -27,7 +28,8 @@ describe('LazyLoadImage', function() {
2728 placeholder = { placeholder }
2829 scrollPosition = { scrollPosition }
2930 src = ""
30- style = { style } />
31+ style = { style }
32+ visibleByDefault = { visibleByDefault } />
3133 ) ;
3234 }
3335
@@ -116,6 +118,16 @@ describe('LazyLoadImage', function() {
116118 expectPlaceholders ( lazyLoadImage , 0 ) ;
117119 } ) ;
118120
121+ it ( 'renders the image when it\'s not in the viewport but visibleByDefault is true' , function ( ) {
122+ const lazyLoadImage = renderLazyLoadImage ( {
123+ style : { marginTop : 100000 } ,
124+ visibleByDefault : true
125+ } ) ;
126+
127+ expectImages ( lazyLoadImage , 1 ) ;
128+ expectPlaceholders ( lazyLoadImage , 0 ) ;
129+ } ) ;
130+
119131 it ( 'doesn\'t trigger beforeLoad when the image is not the viewport' , function ( ) {
120132 const beforeLoad = jest . fn ( ) ;
121133 const lazyLoadImage = renderLazyLoadImage ( {
@@ -148,6 +160,18 @@ describe('LazyLoadImage', function() {
148160 expect ( beforeLoad ) . toHaveBeenCalledTimes ( 1 ) ;
149161 } ) ;
150162
163+ it ( 'triggers beforeLoad when visibleByDefault is true' , function ( ) {
164+ const beforeLoad = jest . fn ( ) ;
165+ const offset = 100000 ;
166+ const lazyLoadImage = renderLazyLoadImage ( {
167+ beforeLoad,
168+ style : { marginTop : offset } ,
169+ visibleByDefault : true
170+ } ) ;
171+
172+ expect ( beforeLoad ) . toHaveBeenCalledTimes ( 1 ) ;
173+ } ) ;
174+
151175 it ( 'doesn\'t trigger afterLoad when the image is not the viewport' , function ( ) {
152176 const afterLoad = jest . fn ( ) ;
153177 const lazyLoadImage = renderLazyLoadImage ( {
@@ -179,4 +203,16 @@ describe('LazyLoadImage', function() {
179203
180204 expect ( afterLoad ) . toHaveBeenCalledTimes ( 1 ) ;
181205 } ) ;
206+
207+ it ( 'triggers afterLoad when visibleByDefault is true' , function ( ) {
208+ const afterLoad = jest . fn ( ) ;
209+ const offset = 100000 ;
210+ const lazyLoadImage = renderLazyLoadImage ( {
211+ afterLoad,
212+ style : { marginTop : offset } ,
213+ visibleByDefault : true
214+ } ) ;
215+
216+ expect ( afterLoad ) . toHaveBeenCalledTimes ( 1 ) ;
217+ } ) ;
182218} ) ;
0 commit comments