@@ -67,6 +67,9 @@ describe('InQueueManager', () => {
67
67
setUserId : function ( s ?: string | null ) {
68
68
userId = s ;
69
69
} ,
70
+ getUserId : function ( ) {
71
+ return userId ;
72
+ } ,
70
73
trackPageView : function ( ) {
71
74
output = attribute ;
72
75
} ,
@@ -183,4 +186,100 @@ describe('InQueueManager', () => {
183
186
] ) ;
184
187
} ) . not . toThrow ( ) ;
185
188
} ) ;
189
+
190
+ it ( 'Executing a custom callback with arguments should pass the arguments to the callback parameters' , ( ) => {
191
+ asyncQueue . push ( [
192
+ function ( a : number , b : number ) {
193
+ expect ( a ) . toEqual ( 1 ) ;
194
+ expect ( b ) . toEqual ( 2 ) ;
195
+ } ,
196
+ 1 ,
197
+ 2 ,
198
+ ] ) ;
199
+ } ) ;
200
+
201
+ it ( 'A custom callback with arguments provided will pass those arguments into the callback parameters' , ( ) => {
202
+ const tracker = newTracker ( 'sp1' ) ;
203
+ mockTrackers . sp1 = tracker ;
204
+
205
+ asyncQueue . push ( [
206
+ function ( a : number , b : number ) {
207
+ expect ( a ) . toEqual ( 1 ) ;
208
+ expect ( b ) . toEqual ( 2 ) ;
209
+ } ,
210
+ 1 ,
211
+ 2 ,
212
+ ] ) ;
213
+
214
+ delete mockTrackers . sp1 ;
215
+ } ) ;
216
+
217
+ it ( 'The callback will be passed the tracker dictionary as the final argument' , ( ) => {
218
+ const mockTracker = newTracker ( 'sp1' ) ;
219
+ mockTracker . setUserId ( 'foo' ) ;
220
+ mockTrackers . sp1 = mockTracker ;
221
+
222
+ asyncQueue . push ( [
223
+ function ( a : number , b : number , trackers : Record < string , any > ) {
224
+ expect ( a ) . toEqual ( 1 ) ;
225
+ expect ( b ) . toEqual ( 2 ) ;
226
+
227
+ const tracker = trackers . sp1 ;
228
+
229
+ expect ( tracker ) . toEqual ( mockTracker ) ;
230
+ expect ( tracker . getUserId ( ) ) . toEqual ( 'foo' ) ;
231
+ } ,
232
+ 1 ,
233
+ 2 ,
234
+ ] ) ;
235
+ delete mockTrackers . sp1 ;
236
+ } ) ;
237
+
238
+ it ( 'The callback will be passed the tracker dictionary as the argument if there is only one parameter' , ( ) => {
239
+ const mockTracker = newTracker ( 'sp1' ) ;
240
+ mockTracker . setUserId ( 'foo' ) ;
241
+ mockTrackers . sp1 = mockTracker ;
242
+
243
+ asyncQueue . push ( [
244
+ function ( trackers : Record < string , any > ) {
245
+ const tracker = trackers . sp1 ;
246
+
247
+ expect ( tracker ) . toEqual ( mockTracker ) ;
248
+ expect ( tracker . getUserId ( ) ) . toEqual ( 'foo' ) ;
249
+ } ,
250
+ ] ) ;
251
+ delete mockTrackers . sp1 ;
252
+ } ) ;
253
+
254
+ it ( 'The callback can access the tracker dictionary using both `this` and the first argument' , ( ) => {
255
+ const mockTracker = newTracker ( 'sp1' ) ;
256
+ mockTracker . setUserId ( 'foo' ) ;
257
+ mockTrackers . sp1 = mockTracker ;
258
+
259
+ asyncQueue . push ( [
260
+ function ( this : any , trackers : Record < string , any > ) {
261
+ expect ( this . sp1 ) . toEqual ( mockTrackers . sp1 ) ;
262
+ expect ( trackers . sp1 ) . toEqual ( mockTrackers . sp1 ) ;
263
+ } ,
264
+ ] ) ;
265
+ delete mockTrackers . sp1 ;
266
+ } ) ;
267
+
268
+ it ( 'The callback can access the tracker dictionary using both `this` and the last argument, along with arguments' , ( ) => {
269
+ const mockTracker = newTracker ( 'sp1' ) ;
270
+ mockTracker . setUserId ( 'foo' ) ;
271
+ mockTrackers . sp1 = mockTracker ;
272
+
273
+ asyncQueue . push ( [
274
+ function ( this : any , a : number , b : number , trackers : Record < string , any > ) {
275
+ expect ( this . sp1 ) . toEqual ( mockTrackers . sp1 ) ;
276
+ expect ( a ) . toEqual ( 1 ) ;
277
+ expect ( b ) . toEqual ( 2 ) ;
278
+ expect ( trackers . sp1 ) . toEqual ( mockTrackers . sp1 ) ;
279
+ } ,
280
+ 1 ,
281
+ 2 ,
282
+ ] ) ;
283
+ delete mockTrackers . sp1 ;
284
+ } ) ;
186
285
} ) ;
0 commit comments