1+ import { ParallaxController } from 'react-scroll-parallax' ;
2+
3+ const addEventListener = window . addEventListener ;
4+ const removeEventListener = window . removeEventListener ;
5+
6+ describe ( 'Expect the ParallaxController' , ( ) => {
7+
8+ afterEach ( ( ) => {
9+ window . addEventListener = addEventListener ;
10+ window . removeEventListener = removeEventListener ;
11+ } ) ;
12+
13+ it ( 'to return an instance on init' , ( ) => {
14+ const instance = ParallaxController . init ( ) ;
15+ expect ( instance ) . toBeInstanceOf ( ParallaxController ) ;
16+ } ) ;
17+
18+ it ( 'to return an existing instance from the window on init' , ( ) => {
19+ window . ParallaxController = 'foo' ;
20+ const instance = ParallaxController . init ( ) ;
21+ expect ( instance ) . toBe ( 'foo' ) ;
22+ window . ParallaxController = undefined ;
23+ } ) ;
24+
25+ it ( 'to throw on init if there\'s no window' ) ;
26+
27+ it ( 'to add listeners when init' , ( ) => {
28+ window . addEventListener = jest . fn ( ) ;
29+ const instance = ParallaxController . init ( ) ;
30+
31+ expect ( window . addEventListener . mock . calls [ 1 ] ) . toEqual (
32+ expect . arrayContaining ( [ 'scroll' , expect . any ( Function ) , false ] )
33+ ) ;
34+ expect ( window . addEventListener . mock . calls [ 2 ] ) . toEqual (
35+ expect . arrayContaining ( [ 'resize' , expect . any ( Function ) , false ] )
36+ ) ;
37+ } ) ;
38+
39+ it ( 'to remove listeners when destroyed' , ( ) => {
40+ window . removeEventListener = jest . fn ( ) ;
41+ const instance = ParallaxController . init ( ) ;
42+
43+ instance . destroy ( ) ;
44+ expect ( window . removeEventListener . mock . calls [ 0 ] ) . toEqual (
45+ expect . arrayContaining ( [ 'scroll' , expect . any ( Function ) , false ] )
46+ ) ;
47+ expect ( window . removeEventListener . mock . calls [ 1 ] ) . toEqual (
48+ expect . arrayContaining ( [ 'resize' , expect . any ( Function ) , false ] )
49+ ) ;
50+ expect ( window . ParallaxController ) . toBe ( null ) ;
51+ } ) ;
52+ } ) ;
0 commit comments