@@ -10,9 +10,10 @@ const {
1010} = ReactTestUtils ;
1111
1212describe ( 'LazyLoadImage' , function ( ) {
13- function renderLazyLoadImage ( scrollPosition ) {
13+ function renderLazyLoadImage ( scrollPosition = 0 , placeholder = null ) {
1414 return ReactTestUtils . renderIntoDocument (
1515 < LazyLoadImage
16+ placeholder = { placeholder }
1617 scrollPosition = { scrollPosition }
1718 src = "" />
1819 ) ;
@@ -24,22 +25,29 @@ describe('LazyLoadImage', function() {
2425 expect ( img . length ) . toEqual ( numberOfImages ) ;
2526 }
2627
27- function expectPlaceholders ( wrapper , numberOfPlaceholders ) {
28- const placeholder = scryRenderedDOMComponentsWithClass ( wrapper ,
29- 'lazy-load-image-placeholder' ) ;
28+ function expectPlaceholders ( wrapper , numberOfPlaceholders , placeholderClassName = 'lazy-load-image-placeholder' ) {
29+ const placeholder = scryRenderedDOMComponentsWithClass ( wrapper , placeholderClassName ) ;
3030
3131 expect ( placeholder . length ) . toEqual ( numberOfPlaceholders ) ;
3232 }
3333
34- it ( 'renders the placeholder when it\'s not in the viewport' , function ( ) {
34+ it ( 'renders the default placeholder when it\'s not in the viewport' , function ( ) {
3535 const lazyLoadImage = renderLazyLoadImage ( - 1000 ) ;
3636
3737 expectImages ( lazyLoadImage , 0 ) ;
3838 expectPlaceholders ( lazyLoadImage , 1 ) ;
3939 } ) ;
4040
41+ it ( 'renders the prop placeholder when it\'s not in the viewport' , function ( ) {
42+ const placeholder = < span className = "test-placeholder" > </ span > ;
43+ const lazyLoadImage = renderLazyLoadImage ( - 1000 , placeholder ) ;
44+
45+ expectImages ( lazyLoadImage , 0 ) ;
46+ expectPlaceholders ( lazyLoadImage , 1 , 'test-placeholder' ) ;
47+ } ) ;
48+
4149 it ( 'renders the image when it\'s in the viewport' , function ( ) {
42- const lazyLoadImage = renderLazyLoadImage ( 0 ) ;
50+ const lazyLoadImage = renderLazyLoadImage ( ) ;
4351
4452 expectImages ( lazyLoadImage , 1 ) ;
4553 expectPlaceholders ( lazyLoadImage , 0 ) ;
0 commit comments