11import React from 'react' ;
2- import { render , cleanup } from '@testing-library/react'
2+ import { render , cleanup } from '@testing-library/react' ;
33import InfiniteScroll from '../index' ;
44
55describe ( 'React Infinite Scroll Component' , ( ) => {
6-
7- afterEach ( cleanup )
6+ afterEach ( cleanup ) ;
87
98 it ( 'renders .infinite-scroll-component' , ( ) => {
109 const { container } = render (
11- < InfiniteScroll
12- dataLength = { 4 }
13- loader = { " Loading..." }
10+ < InfiniteScroll
11+ dataLength = { 4 }
12+ loader = { ' Loading...' }
1413 hasMore = { false }
1514 next = { ( ) => { } }
1615 >
1716 < div />
1817 </ InfiniteScroll >
1918 ) ;
20- expect ( container . querySelectorAll ( '.infinite-scroll-component' ) . length ) . toBe ( 1 )
19+ expect (
20+ container . querySelectorAll ( '.infinite-scroll-component' ) . length
21+ ) . toBe ( 1 ) ;
2122 } ) ;
2223
2324 it ( 'renders custom class' , ( ) => {
2425 const { container } = render (
25- < InfiniteScroll
26- dataLength = { 4 }
27- loader = { " Loading..." }
26+ < InfiniteScroll
27+ dataLength = { 4 }
28+ loader = { ' Loading...' }
2829 className = "custom-class"
2930 hasMore = { false }
3031 next = { ( ) => { } }
@@ -38,26 +39,26 @@ describe('React Infinite Scroll Component', () => {
3839 it ( 'renders children when passed in' , ( ) => {
3940 const { container } = render (
4041 < InfiniteScroll
41- dataLength = { 4 }
42- loader = { " Loading..." }
42+ dataLength = { 4 }
43+ loader = { ' Loading...' }
4344 hasMore = { false }
4445 next = { ( ) => { } }
4546 >
4647 < div className = "child" />
4748 </ InfiniteScroll >
4849 ) ;
49- expect ( container . querySelectorAll ( '.child' ) . length ) . toBe ( 1 )
50+ expect ( container . querySelectorAll ( '.child' ) . length ) . toBe ( 1 ) ;
5051 } ) ;
5152
5253 it ( 'calls scroll handler if provided, when user scrolls' , ( ) => {
5354 jest . useFakeTimers ( ) ;
5455 const onScrollMock = jest . fn ( ) ;
5556
5657 const { container } = render (
57- < InfiniteScroll
58- onScroll = { onScrollMock }
59- dataLength = { 4 }
60- loader = { " Loading..." }
58+ < InfiniteScroll
59+ onScroll = { onScrollMock }
60+ dataLength = { 4 }
61+ loader = { ' Loading...' }
6162 height = { 100 }
6263 hasMore = { false }
6364 next = { ( ) => { } }
@@ -67,7 +68,9 @@ describe('React Infinite Scroll Component', () => {
6768 ) ;
6869
6970 const scrollEvent = new Event ( 'scroll' ) ;
70- const node = container . querySelector ( '.infinite-scroll-component' ) as HTMLElement ;
71+ const node = container . querySelector (
72+ '.infinite-scroll-component'
73+ ) as HTMLElement ;
7174
7275 node . dispatchEvent ( scrollEvent ) ;
7376 jest . runOnlyPendingTimers ( ) ;
@@ -76,12 +79,11 @@ describe('React Infinite Scroll Component', () => {
7679 } ) ;
7780
7881 describe ( 'When user scrolls to the bottom' , ( ) => {
79-
8082 it ( 'does not show loader if hasMore is false' , ( ) => {
8183 const { container, queryByText } = render (
82- < InfiniteScroll
83- dataLength = { 4 }
84- loader = { " Loading..." }
84+ < InfiniteScroll
85+ dataLength = { 4 }
86+ loader = { ' Loading...' }
8587 hasMore = { false }
8688 scrollThreshold = { 0 }
8789 next = { ( ) => { } }
@@ -91,16 +93,18 @@ describe('React Infinite Scroll Component', () => {
9193 ) ;
9294
9395 const scrollEvent = new Event ( 'scroll' ) ;
94- const node = container . querySelector ( '.infinite-scroll-component' ) as HTMLElement ;
96+ const node = container . querySelector (
97+ '.infinite-scroll-component'
98+ ) as HTMLElement ;
9599 node . dispatchEvent ( scrollEvent ) ;
96100 expect ( queryByText ( 'Loading...' ) ) . toBeFalsy ( ) ;
97101 } ) ;
98102
99103 it ( 'shows loader if hasMore is true' , ( ) => {
100104 const { container, getByText } = render (
101- < InfiniteScroll
102- dataLength = { 4 }
103- loader = { " Loading..." }
105+ < InfiniteScroll
106+ dataLength = { 4 }
107+ loader = { ' Loading...' }
104108 hasMore = { true }
105109 scrollThreshold = { 0 }
106110 next = { ( ) => { } }
@@ -111,19 +115,20 @@ describe('React Infinite Scroll Component', () => {
111115 ) ;
112116
113117 const scrollEvent = new Event ( 'scroll' ) ;
114- const node = container . querySelector ( '.infinite-scroll-component' ) as HTMLElement ;
118+ const node = container . querySelector (
119+ '.infinite-scroll-component'
120+ ) as HTMLElement ;
115121 node . dispatchEvent ( scrollEvent ) ;
116122 expect ( getByText ( 'Loading...' ) ) . toBeTruthy ( ) ;
117123 } ) ;
118-
119124 } ) ;
120125
121126 it ( 'shows end message' , ( ) => {
122127 const { queryByText } = render (
123128 < InfiniteScroll
124- dataLength = { 4 }
125- loader = { " Loading..." }
126- endMessage = { " Reached end." }
129+ dataLength = { 4 }
130+ loader = { ' Loading...' }
131+ endMessage = { ' Reached end.' }
127132 hasMore = { false }
128133 next = { ( ) => { } }
129134 >
@@ -132,4 +137,4 @@ describe('React Infinite Scroll Component', () => {
132137 ) ;
133138 expect ( queryByText ( 'Reached end.' ) ) . toBeTruthy ( ) ;
134139 } ) ;
135- } ) ;
140+ } ) ;
0 commit comments