@@ -18,6 +18,8 @@ define([
1818
1919 var injector = new Squire ( ) ,
2020 obj ,
21+ _ ,
22+ originaljQuery ,
2123 originalGetJSON ,
2224 originalReload ,
2325 originalIsEmpty ,
@@ -103,20 +105,22 @@ define([
103105 } ) ;
104106
105107 beforeEach ( function ( done ) {
106- originalGetJSON = jQuery . getJSON ;
108+ originalGetJSON = $ . getJSON ;
107109 sectionConfig [ 'Magento_Customer/js/section-config' ] ( sectionConfigSettings ) ;
108110
109111 injector . require ( [
112+ 'underscore' ,
110113 'Magento_Customer/js/customer-data'
111- ] , function ( Constr ) {
114+ ] , function ( underscore , Constr ) {
115+ _ = underscore ;
112116 obj = Constr ;
113117 done ( ) ;
114118 } ) ;
115119 } ) ;
116120
117121 afterEach ( function ( ) {
118122 try {
119- jQuery . getJSON = originalGetJSON ;
123+ $ . getJSON = originalGetJSON ;
120124 clearLocalStorage ( ) ;
121125 injector . clean ( ) ;
122126 injector . remove ( ) ;
@@ -125,14 +129,20 @@ define([
125129 } ) ;
126130
127131 describe ( '"init" method' , function ( ) {
132+ var storageInvalidation = {
133+ keys : function ( ) {
134+ return [ 'section' ] ;
135+ }
136+ } ;
137+
128138 beforeEach ( function ( ) {
129139 originalReload = obj . reload ;
130140 originalIsEmpty = _ . isEmpty ;
131141
132- spyOn ( obj , 'reload' ) . and . returnValue ( true ) ;
133-
134142 $ . initNamespaceStorage ( 'mage-cache-storage' ) . localStorage ;
135143 $ . initNamespaceStorage ( 'mage-cache-storage-section-invalidation' ) . localStorage ;
144+
145+ spyOn ( storageInvalidation , 'keys' ) . and . returnValue ( [ 'section' ] ) ;
136146 } ) ;
137147
138148 afterEach ( function ( ) {
@@ -161,13 +171,15 @@ define([
161171
162172 it ( 'Calls "reload" method when expired sections exist' , function ( ) {
163173 spyOn ( obj , 'getExpiredSectionNames' ) . and . returnValue ( [ 'section' ] ) ;
174+ spyOn ( obj , 'reload' ) . and . returnValue ( true ) ;
164175 obj . init ( ) ;
165176 expect ( obj . reload ) . toHaveBeenCalled ( ) ;
166177 } ) ;
167178
168179 it ( 'Calls "reload" method when expired sections do not exist' , function ( ) {
169180 spyOn ( obj , 'getExpiredSectionNames' ) . and . returnValue ( [ ] ) ;
170- _ . isEmpty = jasmine . createSpy ( '_.isEmpty' ) . and . returnValue ( false ) ;
181+ spyOn ( obj , 'reload' ) . and . returnValue ( true ) ;
182+ spyOn ( _ , 'isEmpty' ) . and . returnValue ( false ) ;
171183
172184 obj . init ( ) ;
173185 expect ( obj . reload ) . toHaveBeenCalled ( ) ;
@@ -180,14 +192,14 @@ define([
180192 }
181193 } ) ;
182194
183- jQuery . getJSON = jasmine . createSpy ( ) . and . callFake ( function ( ) {
195+ $ . getJSON = jasmine . createSpy ( ) . and . callFake ( function ( ) {
184196 var deferred = $ . Deferred ( ) ;
185197
186198 return deferred . promise ( ) ;
187199 } ) ;
188200
189201 init ( ) ;
190- expect ( jQuery . getJSON ) . not . toHaveBeenCalled ( ) ;
202+ expect ( $ . getJSON ) . not . toHaveBeenCalled ( ) ;
191203 } ) ;
192204
193205 it ( 'Check it requests sections from the server if there are expired sections' , function ( ) {
@@ -246,6 +258,13 @@ define([
246258 'content' : { }
247259 }
248260 } ) ;
261+
262+ $ . getJSON = jasmine . createSpy ( '$.getJSON' ) . and . callFake ( function ( ) {
263+ var deferred = $ . Deferred ( ) ;
264+
265+ return deferred . promise ( ) ;
266+ } ) ;
267+
249268 init ( ) ;
250269 expect ( customerData . getExpiredSectionNames ( ) ) . toEqual ( [ 'cart' ] ) ;
251270 } ) ;
@@ -268,6 +287,12 @@ define([
268287 }
269288 } ) ;
270289
290+ $ . getJSON = jasmine . createSpy ( '$.getJSON' ) . and . callFake ( function ( ) {
291+ var deferred = $ . Deferred ( ) ;
292+
293+ return deferred . promise ( ) ;
294+ } ) ;
295+
271296 init ( ) ;
272297 expect ( customerData . getExpiredSectionNames ( ) ) . toEqual ( [ 'cart' ] ) ;
273298 } ) ;
@@ -320,7 +345,10 @@ define([
320345
321346 describe ( '"reload" method' , function ( ) {
322347 beforeEach ( function ( ) {
323- jQuery . getJSON = jasmine . createSpy ( ) . and . callFake ( function ( ) {
348+ originaljQuery = $ ;
349+ $ = jQuery ;
350+
351+ $ . getJSON = jasmine . createSpy ( ) . and . callFake ( function ( ) {
324352 var deferred = $ . Deferred ( ) ;
325353
326354 /**
@@ -339,6 +367,10 @@ define([
339367 } ) ;
340368 } ) ;
341369
370+ afterEach ( function ( ) {
371+ $ = originaljQuery ;
372+ } ) ;
373+
342374 it ( 'Should be defined' , function ( ) {
343375 expect ( obj . hasOwnProperty ( 'reload' ) ) . toBeDefined ( ) ;
344376 } ) ;
@@ -354,7 +386,7 @@ define([
354386
355387 spyOn ( sectionConfig , 'filterClientSideSections' ) . and . returnValue ( [ 'section' ] ) ;
356388
357- jQuery . getJSON = jasmine . createSpy ( ) . and . callFake ( function ( url , parameters ) {
389+ $ . getJSON = jasmine . createSpy ( ) . and . callFake ( function ( url , parameters ) {
358390 var deferred = $ . Deferred ( ) ;
359391
360392 /**
@@ -390,7 +422,7 @@ define([
390422
391423 spyOn ( sectionConfig , 'filterClientSideSections' ) . and . returnValue ( [ 'cart,customer,messages' ] ) ;
392424
393- jQuery . getJSON = jasmine . createSpy ( ) . and . callFake ( function ( url , parameters ) {
425+ $ . getJSON = jasmine . createSpy ( ) . and . callFake ( function ( url , parameters ) {
394426 var deferred = $ . Deferred ( ) ;
395427
396428 expect ( parameters ) . toEqual ( jasmine . objectContaining ( {
@@ -428,7 +460,7 @@ define([
428460 it ( 'Check it returns all sections when passed wildcard string' , function ( ) {
429461 var result ;
430462
431- jQuery . getJSON = jasmine . createSpy ( ) . and . callFake ( function ( url , parameters ) {
463+ $ . getJSON = jasmine . createSpy ( ) . and . callFake ( function ( url , parameters ) {
432464 var deferred = $ . Deferred ( ) ;
433465
434466 expect ( parameters ) . toEqual ( jasmine . objectContaining ( {
@@ -454,7 +486,7 @@ define([
454486
455487 result = obj . reload ( '*' , true ) ;
456488
457- expect ( jQuery . getJSON ) . toHaveBeenCalled ( ) ;
489+ expect ( $ . getJSON ) . toHaveBeenCalled ( ) ;
458490 expect ( result ) . toEqual ( jasmine . objectContaining ( {
459491 responseJSON : {
460492 cart : { } ,
0 commit comments