@@ -10,23 +10,23 @@ describe('Expect the ParallaxController', () => {
10
10
} ) ;
11
11
12
12
it ( 'to return an instance on init' , ( ) => {
13
- const instance = ParallaxController . init ( ) ;
14
- expect ( instance ) . toBeInstanceOf ( ParallaxController ) ;
13
+ const controller = ParallaxController . init ( ) ;
14
+ expect ( controller ) . toBeInstanceOf ( ParallaxController ) ;
15
15
} ) ;
16
16
17
- it ( 'to return an existing instance from the window on init' , ( ) => {
18
- window . ParallaxController = 'foo' ;
19
- const instance = ParallaxController . init ( ) ;
20
- expect ( instance ) . toBe ( 'foo' ) ;
21
- window . ParallaxController = undefined ;
17
+ it ( 'to copy the instance to a legacy global on init' , ( ) => {
18
+ const controller = ParallaxController . init ( ) ;
19
+ expect ( window . ParallaxController ) . toBeInstanceOf ( ParallaxController ) ;
22
20
} ) ;
23
21
24
22
it ( "to throw on init if there's no window" ) ;
25
23
26
24
it ( 'to add listeners when init' , ( ) => {
27
25
window . addEventListener = jest . fn ( ) ;
28
- const instance = ParallaxController . init ( ) ;
29
-
26
+ const controller = ParallaxController . init ( ) ;
27
+ expect ( window . addEventListener . mock . calls [ 0 ] ) . toEqual (
28
+ expect . arrayContaining ( [ 'test' , null , expect . any ( Object ) ] )
29
+ ) ;
30
30
expect ( window . addEventListener . mock . calls [ 1 ] ) . toEqual (
31
31
expect . arrayContaining ( [ 'scroll' , expect . any ( Function ) , false ] )
32
32
) ;
@@ -36,7 +36,7 @@ describe('Expect the ParallaxController', () => {
36
36
} ) ;
37
37
38
38
it ( 'to create an element and return it' , ( ) => {
39
- const instance = ParallaxController . init ( ) ;
39
+ const controller = ParallaxController . init ( ) ;
40
40
const options = {
41
41
elInner : document . createElement ( 'div' ) ,
42
42
elOuter : document . createElement ( 'div' ) ,
@@ -49,7 +49,7 @@ describe('Expect the ParallaxController', () => {
49
49
slowerScrollRate : false ,
50
50
} ,
51
51
} ;
52
- const element = instance . createElement ( options ) ;
52
+ const element = controller . createElement ( options ) ;
53
53
54
54
const expectedElement = {
55
55
attributes : {
@@ -88,8 +88,8 @@ describe('Expect the ParallaxController', () => {
88
88
89
89
it ( 'to update the controller when creating an element' , ( ) => {
90
90
window . removeEventListener = jest . fn ( ) ;
91
- window . ParallaxController = ParallaxController . init ( ) ;
92
- window . ParallaxController . update = jest . fn ( ) ;
91
+ const controller = ParallaxController . init ( ) ;
92
+ controller . update = jest . fn ( ) ;
93
93
94
94
const options = {
95
95
elInner : document . createElement ( 'div' ) ,
@@ -104,15 +104,15 @@ describe('Expect the ParallaxController', () => {
104
104
} ,
105
105
} ;
106
106
107
- window . ParallaxController . createElement ( options ) ;
108
- expect ( window . ParallaxController . update ) . toBeCalled ( ) ;
109
- window . ParallaxController . destroy ( ) ;
107
+ controller . createElement ( options ) ;
108
+ expect ( controller . update ) . toBeCalled ( ) ;
109
+ controller . destroy ( ) ;
110
110
} ) ;
111
111
112
112
it ( 'to update the controller when updating an element' , ( ) => {
113
113
window . removeEventListener = jest . fn ( ) ;
114
- window . ParallaxController = ParallaxController . init ( ) ;
115
- window . ParallaxController . update = jest . fn ( ) ;
114
+ const controller = ParallaxController . init ( ) ;
115
+ controller . update = jest . fn ( ) ;
116
116
117
117
const options = {
118
118
elInner : document . createElement ( 'div' ) ,
@@ -127,18 +127,18 @@ describe('Expect the ParallaxController', () => {
127
127
} ,
128
128
} ;
129
129
130
- const element = window . ParallaxController . createElement ( options ) ;
131
- window . ParallaxController . updateElement ( element , {
130
+ const element = controller . createElement ( options ) ;
131
+ controller . updateElement ( element , {
132
132
prop : { disabled : false } ,
133
133
} ) ;
134
- expect ( window . ParallaxController . update ) . toBeCalled ( ) ;
135
- window . ParallaxController . destroy ( ) ;
134
+ expect ( controller . update ) . toBeCalled ( ) ;
135
+ controller . destroy ( ) ;
136
136
} ) ;
137
137
138
138
it ( 'to create an element then update the controller' , ( ) => {
139
139
window . removeEventListener = jest . fn ( ) ;
140
- window . ParallaxController = ParallaxController . init ( ) ;
141
- window . ParallaxController . update = jest . fn ( ) ;
140
+ const controller = ParallaxController . init ( ) ;
141
+ controller . update = jest . fn ( ) ;
142
142
143
143
const options = {
144
144
elInner : document . createElement ( 'div' ) ,
@@ -153,22 +153,24 @@ describe('Expect the ParallaxController', () => {
153
153
} ,
154
154
} ;
155
155
156
- window . ParallaxController . createElement ( options ) ;
156
+ controller . createElement ( options ) ;
157
157
158
- expect ( window . ParallaxController . update ) . toBeCalled ( ) ;
158
+ expect ( controller . update ) . toBeCalled ( ) ;
159
159
} ) ;
160
160
161
161
it ( 'to remove listeners when destroyed' , ( ) => {
162
162
window . removeEventListener = jest . fn ( ) ;
163
163
const instance = ParallaxController . init ( ) ;
164
+ expect ( window . removeEventListener . mock . calls [ 0 ] ) . toEqual (
165
+ expect . arrayContaining ( [ 'test' , null , expect . any ( Object ) ] )
166
+ ) ;
164
167
165
168
instance . destroy ( ) ;
166
- expect ( window . removeEventListener . mock . calls [ 0 ] ) . toEqual (
169
+ expect ( window . removeEventListener . mock . calls [ 1 ] ) . toEqual (
167
170
expect . arrayContaining ( [ 'scroll' , expect . any ( Function ) , false ] )
168
171
) ;
169
- expect ( window . removeEventListener . mock . calls [ 1 ] ) . toEqual (
172
+ expect ( window . removeEventListener . mock . calls [ 2 ] ) . toEqual (
170
173
expect . arrayContaining ( [ 'resize' , expect . any ( Function ) , false ] )
171
174
) ;
172
- expect ( window . ParallaxController ) . toBe ( null ) ;
173
175
} ) ;
174
176
} ) ;
0 commit comments