@@ -272,7 +272,19 @@ describe('calling some action inside the events options', () => {
272
272
} ) ;
273
273
describe ( 'select method : ' , ( ) => {
274
274
test ( 'it should fire onInit event then onChange and then onSelect evnets' , ( ) => {
275
- const onSelect = jest . fn ( ( ) => { } ) ;
275
+ const executionOrder = [ ] ;
276
+ op . onInit = jest . fn ( ( ) => {
277
+ executionOrder . push ( 'onInit' ) ;
278
+ } ) ;
279
+ op . onChange = jest . fn ( ( ) => {
280
+ executionOrder . push ( 'onChange' ) ;
281
+ } ) ;
282
+ op . onSelect = jest . fn ( ( ) => {
283
+ executionOrder . push ( 'onSelect' ) ;
284
+ } ) ;
285
+ const onSelect = jest . fn ( ( ) => {
286
+ executionOrder . push ( 'onSelect2' ) ;
287
+ } ) ;
276
288
renderApp ( ) ;
277
289
act ( ( ) => {
278
290
instance . one ( 'onSelect' , onSelect ) . select ( '2' ) ;
@@ -284,9 +296,7 @@ describe('select method : ', () => {
284
296
currentSelectedTabId : '2' ,
285
297
previousSelectedTabId : '1' ,
286
298
} ) ;
287
- expect ( op . onInit ) . toHaveBeenCalledBefore ( op . onChange ) ;
288
- expect ( op . onChange ) . toHaveBeenCalledBefore ( op . onSelect ) ;
289
- expect ( op . onSelect ) . toHaveBeenCalledBefore ( onSelect ) ;
299
+ expect ( executionOrder . toString ( ) ) . toBe ( 'onInit,onInit,onChange,onSelect,onSelect2' ) ;
290
300
} ) ;
291
301
test ( 'select Promise is resolved with {currentData,instance} parameter after onSelect event' , ( ) => {
292
302
expect . assertions ( 6 ) ;
@@ -327,7 +337,19 @@ describe('select method : ', () => {
327
337
} ) ;
328
338
describe ( 'close method : ' , ( ) => {
329
339
test ( 'it should fire onInit event then onChange and then onClose evnets' , ( ) => {
330
- const onClose = jest . fn ( ( ) => { } ) ;
340
+ const executionOrder = [ ] ;
341
+ op . onInit = jest . fn ( ( ) => {
342
+ executionOrder . push ( 'onInit' ) ;
343
+ } ) ;
344
+ op . onChange = jest . fn ( ( ) => {
345
+ executionOrder . push ( 'onChange' ) ;
346
+ } ) ;
347
+ op . onClose = jest . fn ( ( ) => {
348
+ executionOrder . push ( 'onClose' ) ;
349
+ } ) ;
350
+ const onClose = jest . fn ( ( ) => {
351
+ executionOrder . push ( 'onClose2' ) ;
352
+ } ) ;
331
353
renderApp ( ) ;
332
354
act ( ( ) => {
333
355
instance . one ( 'onClose' , onClose ) . close ( '2' ) ;
@@ -337,9 +359,7 @@ describe('close method : ', () => {
337
359
expect ( op . onClose . mock . calls . length === 1 ) . toBe ( true ) ;
338
360
expect ( op . onClose . mock . calls [ 0 ] [ 0 ] ) . toEqual ( [ '2' ] ) ;
339
361
expect ( onClose . mock . calls [ 0 ] [ 0 ] ) . toEqual ( [ '2' ] ) ;
340
- expect ( op . onInit ) . toHaveBeenCalledBefore ( op . onChange ) ;
341
- expect ( op . onChange ) . toHaveBeenCalledBefore ( op . onClose ) ;
342
- expect ( op . onClose ) . toHaveBeenCalledBefore ( onClose ) ;
362
+ expect ( executionOrder . toString ( ) ) . toBe ( 'onInit,onInit,onChange,onClose,onClose2' ) ;
343
363
} ) ;
344
364
test ( 'close Promise is resolved with {currentData,instance} parameter after onClose event' , ( ) => {
345
365
expect . assertions ( 6 ) ;
@@ -368,7 +388,19 @@ describe('close method : ', () => {
368
388
} ) ;
369
389
describe ( 'open method : ' , ( ) => {
370
390
test ( 'it should fire onInit event then onChange and then onOpen evnets' , ( ) => {
371
- const onOpen = jest . fn ( ( ) => { } ) ;
391
+ const executionOrder = [ ] ;
392
+ op . onInit = jest . fn ( ( ) => {
393
+ executionOrder . push ( 'onInit' ) ;
394
+ } ) ;
395
+ op . onChange = jest . fn ( ( ) => {
396
+ executionOrder . push ( 'onChange' ) ;
397
+ } ) ;
398
+ op . onOpen = jest . fn ( ( ) => {
399
+ executionOrder . push ( 'onOpen' ) ;
400
+ } ) ;
401
+ const onOpen = jest . fn ( ( ) => {
402
+ executionOrder . push ( 'onOpen2' ) ;
403
+ } ) ;
372
404
renderApp ( ) ;
373
405
act ( ( ) => {
374
406
instance . one ( 'onOpen' , onOpen ) . open ( {
@@ -385,9 +417,7 @@ describe('open method : ', () => {
385
417
expect ( op . onOpen . mock . calls . length === 1 ) . toBe ( true ) ;
386
418
expect ( op . onOpen . mock . calls [ 0 ] [ 0 ] ) . toEqual ( [ '3' , '4' ] ) ;
387
419
expect ( onOpen . mock . calls [ 0 ] [ 0 ] ) . toEqual ( [ '3' , '4' ] ) ;
388
- expect ( op . onInit ) . toHaveBeenCalledBefore ( op . onChange ) ;
389
- expect ( op . onChange ) . toHaveBeenCalledBefore ( op . onOpen ) ;
390
- expect ( op . onOpen ) . toHaveBeenCalledBefore ( onOpen ) ;
420
+ expect ( executionOrder . toString ( ) ) . toBe ( 'onInit,onInit,onChange,onOpen,onOpen2' ) ;
391
421
} ) ;
392
422
test ( 'open Promise is resolved with {currentData,instance} parameter after onOpen event' , ( ) => {
393
423
expect . assertions ( 5 ) ;
@@ -498,15 +528,23 @@ describe('ready function : ', () => {
498
528
} ) ;
499
529
} ) ;
500
530
test ( 'it calls its function parameter after onLoad event and first execution of onInit event' , ( ) => {
501
- expect . assertions ( 6 ) ;
502
- const onReady = jest . fn ( ( ) => { } ) ;
531
+ expect . assertions ( 5 ) ;
532
+ const executionOrder = [ ] ;
533
+ const onReady = jest . fn ( ( ) => {
534
+ executionOrder . push ( 'onReady' ) ;
535
+ } ) ;
536
+ op . onLoad = jest . fn ( ( ) => {
537
+ executionOrder . push ( 'onLoad' ) ;
538
+ } ) ;
539
+ op . onInit = jest . fn ( ( ) => {
540
+ executionOrder . push ( 'onInit' ) ;
541
+ } ) ;
503
542
renderApp ( ) ;
504
543
ready ( onReady ) ;
505
544
expect ( op . onLoad . mock . calls . length === 1 ) . toBe ( true ) ;
506
545
expect ( op . onInit . mock . calls . length === 1 ) . toBe ( true ) ;
507
546
expect ( onReady . mock . calls . length === 1 ) . toBe ( true ) ;
508
- expect ( op . onLoad ) . toHaveBeenCalledBefore ( op . onInit ) ;
509
- expect ( op . onInit ) . toHaveBeenCalledBefore ( onReady ) ;
547
+ expect ( executionOrder . toString ( ) ) . toBe ( 'onLoad,onInit,onReady' ) ;
510
548
expect ( op . onChange . mock . calls . length ) . toBe ( 0 ) ;
511
549
} ) ;
512
550
} ) ;
@@ -685,6 +723,13 @@ describe('onFirstSelect callback : ', () => {
685
723
expect ( op . onFirstSelect . mock . calls . length ) . toBe ( 0 ) ;
686
724
} ) ;
687
725
test ( 'it is triggered at most once per each tab, before onSelect event. if the tab has not been selected yet' , ( ) => {
726
+ const executionOrder = [ ] ;
727
+ op . onFirstSelect = jest . fn ( ( ) => {
728
+ executionOrder . push ( 'onFirstSelect' ) ;
729
+ } ) ;
730
+ op . onSelect = jest . fn ( ( ) => {
731
+ executionOrder . push ( 'onSelect' ) ;
732
+ } ) ;
688
733
renderApp ( ) ;
689
734
expect ( op . onFirstSelect . mock . calls . length ) . toBe ( 0 ) ;
690
735
expect ( op . onSelect . mock . calls . length ) . toBe ( 0 ) ;
@@ -693,7 +738,7 @@ describe('onFirstSelect callback : ', () => {
693
738
} ) ;
694
739
expect ( op . onFirstSelect . mock . calls . length ) . toBe ( 1 ) ;
695
740
expect ( op . onSelect . mock . calls . length ) . toBe ( 1 ) ;
696
- expect ( op . onFirstSelect ) . toHaveBeenCalledBefore ( op . onSelect ) ;
741
+ expect ( executionOrder . toString ( ) ) . toBe ( 'onFirstSelect, onSelect' ) ;
697
742
act ( ( ) => {
698
743
instance . select ( '1' ) ;
699
744
} ) ;
0 commit comments