@@ -10,23 +10,23 @@ describe('Expect the ParallaxController', () => {
1010 } ) ;
1111
1212 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 ) ;
1515 } ) ;
1616
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 ) ;
2220 } ) ;
2321
2422 it ( "to throw on init if there's no window" ) ;
2523
2624 it ( 'to add listeners when init' , ( ) => {
2725 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+ ) ;
3030 expect ( window . addEventListener . mock . calls [ 1 ] ) . toEqual (
3131 expect . arrayContaining ( [ 'scroll' , expect . any ( Function ) , false ] )
3232 ) ;
@@ -36,7 +36,7 @@ describe('Expect the ParallaxController', () => {
3636 } ) ;
3737
3838 it ( 'to create an element and return it' , ( ) => {
39- const instance = ParallaxController . init ( ) ;
39+ const controller = ParallaxController . init ( ) ;
4040 const options = {
4141 elInner : document . createElement ( 'div' ) ,
4242 elOuter : document . createElement ( 'div' ) ,
@@ -49,7 +49,7 @@ describe('Expect the ParallaxController', () => {
4949 slowerScrollRate : false ,
5050 } ,
5151 } ;
52- const element = instance . createElement ( options ) ;
52+ const element = controller . createElement ( options ) ;
5353
5454 const expectedElement = {
5555 attributes : {
@@ -88,8 +88,8 @@ describe('Expect the ParallaxController', () => {
8888
8989 it ( 'to update the controller when creating an element' , ( ) => {
9090 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 ( ) ;
9393
9494 const options = {
9595 elInner : document . createElement ( 'div' ) ,
@@ -104,15 +104,15 @@ describe('Expect the ParallaxController', () => {
104104 } ,
105105 } ;
106106
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 ( ) ;
110110 } ) ;
111111
112112 it ( 'to update the controller when updating an element' , ( ) => {
113113 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 ( ) ;
116116
117117 const options = {
118118 elInner : document . createElement ( 'div' ) ,
@@ -127,18 +127,18 @@ describe('Expect the ParallaxController', () => {
127127 } ,
128128 } ;
129129
130- const element = window . ParallaxController . createElement ( options ) ;
131- window . ParallaxController . updateElement ( element , {
130+ const element = controller . createElement ( options ) ;
131+ controller . updateElement ( element , {
132132 prop : { disabled : false } ,
133133 } ) ;
134- expect ( window . ParallaxController . update ) . toBeCalled ( ) ;
135- window . ParallaxController . destroy ( ) ;
134+ expect ( controller . update ) . toBeCalled ( ) ;
135+ controller . destroy ( ) ;
136136 } ) ;
137137
138138 it ( 'to create an element then update the controller' , ( ) => {
139139 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 ( ) ;
142142
143143 const options = {
144144 elInner : document . createElement ( 'div' ) ,
@@ -153,22 +153,24 @@ describe('Expect the ParallaxController', () => {
153153 } ,
154154 } ;
155155
156- window . ParallaxController . createElement ( options ) ;
156+ controller . createElement ( options ) ;
157157
158- expect ( window . ParallaxController . update ) . toBeCalled ( ) ;
158+ expect ( controller . update ) . toBeCalled ( ) ;
159159 } ) ;
160160
161161 it ( 'to remove listeners when destroyed' , ( ) => {
162162 window . removeEventListener = jest . fn ( ) ;
163163 const instance = ParallaxController . init ( ) ;
164+ expect ( window . removeEventListener . mock . calls [ 0 ] ) . toEqual (
165+ expect . arrayContaining ( [ 'test' , null , expect . any ( Object ) ] )
166+ ) ;
164167
165168 instance . destroy ( ) ;
166- expect ( window . removeEventListener . mock . calls [ 0 ] ) . toEqual (
169+ expect ( window . removeEventListener . mock . calls [ 1 ] ) . toEqual (
167170 expect . arrayContaining ( [ 'scroll' , expect . any ( Function ) , false ] )
168171 ) ;
169- expect ( window . removeEventListener . mock . calls [ 1 ] ) . toEqual (
172+ expect ( window . removeEventListener . mock . calls [ 2 ] ) . toEqual (
170173 expect . arrayContaining ( [ 'resize' , expect . any ( Function ) , false ] )
171174 ) ;
172- expect ( window . ParallaxController ) . toBe ( null ) ;
173175 } ) ;
174176} ) ;
0 commit comments