3
3
* See COPYING.txt for license details.
4
4
*/
5
5
6
+ /* global _ */
6
7
/* eslint max-nested-callbacks: 0 */
7
-
8
8
define ( [
9
9
'squire' ,
10
10
'jquery' ,
@@ -14,6 +14,10 @@ define([
14
14
15
15
var injector = new Squire ( ) ,
16
16
sectionConfig ,
17
+ originalGetJSON ,
18
+ originalReload ,
19
+ originalInitNamespaceStorage ,
20
+ originalEach ,
17
21
obj ;
18
22
19
23
describe ( 'Magento_Customer/js/customer-data' , function ( ) {
@@ -39,27 +43,46 @@ define([
39
43
40
44
describe ( '"init" method' , function ( ) {
41
45
var storageInvalidation = {
46
+ /**
47
+ * Mock Keys Method
48
+ * @returns array
49
+ */
42
50
keys : function ( ) {
43
51
return [ 'section' ] ;
44
52
}
45
53
} ,
46
54
dataProvider = {
55
+ /**
56
+ * Mock getFromStorage Method
57
+ * @returns array
58
+ */
47
59
getFromStorage : function ( ) {
48
60
return [ 'section' ] ;
49
61
}
50
62
} ,
51
63
storage = {
64
+ /**
65
+ * Mock Keys Method
66
+ * @returns array
67
+ */
52
68
keys : function ( ) {
53
69
return [ 'section' ] ;
54
70
}
55
71
} ;
56
72
57
73
beforeEach ( function ( ) {
58
- spyOn ( obj , "reload" ) . and . returnValue ( true ) ;
74
+ originalReload = obj . reload ;
75
+ originalInitNamespaceStorage = $ . initNamespaceStorage ;
76
+ spyOn ( obj , 'reload' ) . and . returnValue ( true ) ;
59
77
spyOn ( $ , 'initNamespaceStorage' ) . and . returnValue ( true ) ;
60
- spyOn ( dataProvider , "getFromStorage" ) ;
61
- spyOn ( storage , "keys" ) . and . returnValue ( [ 'section' ] ) ;
62
- spyOn ( storageInvalidation , "keys" ) . and . returnValue ( [ 'section' ] ) ;
78
+ spyOn ( dataProvider , 'getFromStorage' ) ;
79
+ spyOn ( storage , 'keys' ) . and . returnValue ( [ 'section' ] ) ;
80
+ spyOn ( storageInvalidation , 'keys' ) . and . returnValue ( [ 'section' ] ) ;
81
+ } ) ;
82
+
83
+ afterEach ( function ( ) {
84
+ obj . reload = originalReload ;
85
+ $ . initNameSpaceStorage = originalInitNamespaceStorage ;
63
86
} ) ;
64
87
65
88
it ( 'Should be defined' , function ( ) {
@@ -73,19 +96,19 @@ define([
73
96
} ) ;
74
97
75
98
it ( 'Calls "getExpiredSectionNames" method' , function ( ) {
76
- spyOn ( obj , " getExpiredSectionNames" ) . and . returnValue ( [ ] ) ;
99
+ spyOn ( obj , ' getExpiredSectionNames' ) . and . returnValue ( [ ] ) ;
77
100
obj . init ( ) ;
78
101
expect ( obj . getExpiredSectionNames ) . toHaveBeenCalled ( ) ;
79
102
} ) ;
80
103
81
104
it ( 'Calls "reload" method when expired sections exist' , function ( ) {
82
- spyOn ( obj , " getExpiredSectionNames" ) . and . returnValue ( [ 'section' ] ) ;
105
+ spyOn ( obj , ' getExpiredSectionNames' ) . and . returnValue ( [ 'section' ] ) ;
83
106
obj . init ( ) ;
84
107
expect ( obj . reload ) . toHaveBeenCalled ( ) ;
85
108
} ) ;
86
109
87
110
it ( 'Calls "reload" method when expired sections do not exist' , function ( ) {
88
- spyOn ( obj , " getExpiredSectionNames" ) . and . returnValue ( [ ] ) ;
111
+ spyOn ( obj , ' getExpiredSectionNames' ) . and . returnValue ( [ ] ) ;
89
112
90
113
_ . isEmpty = jasmine . createSpy ( ) . and . returnValue ( false ) ;
91
114
@@ -119,6 +142,14 @@ define([
119
142
} ) ;
120
143
121
144
describe ( '"set" method' , function ( ) {
145
+ beforeEach ( function ( ) {
146
+ originalEach = _ . each ;
147
+ } ) ;
148
+
149
+ afterEach ( function ( ) {
150
+ _ . each = originalEach ;
151
+ } ) ;
152
+
122
153
it ( 'Should be defined' , function ( ) {
123
154
expect ( obj . hasOwnProperty ( 'set' ) ) . toBeDefined ( ) ;
124
155
} ) ;
@@ -134,9 +165,14 @@ define([
134
165
135
166
describe ( '"reload" method' , function ( ) {
136
167
beforeEach ( function ( ) {
137
- jQuery . getJSON = jasmine . createSpy ( ) . and . callFake ( function ( url , parameters ) {
168
+ originalGetJSON = jQuery . getJSON ;
169
+ jQuery . getJSON = jasmine . createSpy ( ) . and . callFake ( function ( ) {
138
170
var deferred = $ . Deferred ( ) ;
139
171
172
+ /**
173
+ * Mock Done Method for getJSON
174
+ * @returns object
175
+ */
140
176
deferred . promise ( ) . done = function ( ) {
141
177
return {
142
178
responseJSON : {
@@ -149,6 +185,10 @@ define([
149
185
} ) ;
150
186
} ) ;
151
187
188
+ afterEach ( function ( ) {
189
+ jQuery . getJSON = originalGetJSON ;
190
+ } ) ;
191
+
152
192
it ( 'Should be defined' , function ( ) {
153
193
expect ( obj . hasOwnProperty ( 'reload' ) ) . toBeDefined ( ) ;
154
194
} ) ;
@@ -167,6 +207,10 @@ define([
167
207
jQuery . getJSON = jasmine . createSpy ( ) . and . callFake ( function ( url , parameters ) {
168
208
var deferred = $ . Deferred ( ) ;
169
209
210
+ /**
211
+ * Mock Done Method for getJSON
212
+ * @returns object
213
+ */
170
214
deferred . promise ( ) . done = function ( ) {
171
215
return {
172
216
responseJSON : {
@@ -176,7 +220,7 @@ define([
176
220
} ;
177
221
178
222
expect ( parameters ) . toEqual ( jasmine . objectContaining ( {
179
- " sections" : " section"
223
+ sections : ' section'
180
224
} ) ) ;
181
225
182
226
return deferred . promise ( ) ;
@@ -200,9 +244,13 @@ define([
200
244
var deferred = $ . Deferred ( ) ;
201
245
202
246
expect ( parameters ) . toEqual ( jasmine . objectContaining ( {
203
- " sections" : " cart,customer,messages"
247
+ sections : ' cart,customer,messages'
204
248
} ) ) ;
205
249
250
+ /**
251
+ * Mock Done Method for getJSON
252
+ * @returns object
253
+ */
206
254
deferred . promise ( ) . done = function ( ) {
207
255
return {
208
256
responseJSON : {
@@ -234,9 +282,13 @@ define([
234
282
var deferred = $ . Deferred ( ) ;
235
283
236
284
expect ( parameters ) . toEqual ( jasmine . objectContaining ( {
237
- " force_new_section_timestamp" : true
285
+ ' force_new_section_timestamp' : true
238
286
} ) ) ;
239
287
288
+ /**
289
+ * Mock Done Method for getJSON
290
+ * @returns object
291
+ */
240
292
deferred . promise ( ) . done = function ( ) {
241
293
return {
242
294
responseJSON : {
0 commit comments