@@ -272,7 +272,19 @@ describe('calling some action inside the events options', () => {
272272} ) ;
273273describe ( 'select method : ' , ( ) => {
274274 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+ } ) ;
276288 renderApp ( ) ;
277289 act ( ( ) => {
278290 instance . one ( 'onSelect' , onSelect ) . select ( '2' ) ;
@@ -284,9 +296,7 @@ describe('select method : ', () => {
284296 currentSelectedTabId : '2' ,
285297 previousSelectedTabId : '1' ,
286298 } ) ;
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' ) ;
290300 } ) ;
291301 test ( 'select Promise is resolved with {currentData,instance} parameter after onSelect event' , ( ) => {
292302 expect . assertions ( 6 ) ;
@@ -327,7 +337,19 @@ describe('select method : ', () => {
327337} ) ;
328338describe ( 'close method : ' , ( ) => {
329339 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+ } ) ;
331353 renderApp ( ) ;
332354 act ( ( ) => {
333355 instance . one ( 'onClose' , onClose ) . close ( '2' ) ;
@@ -337,9 +359,7 @@ describe('close method : ', () => {
337359 expect ( op . onClose . mock . calls . length === 1 ) . toBe ( true ) ;
338360 expect ( op . onClose . mock . calls [ 0 ] [ 0 ] ) . toEqual ( [ '2' ] ) ;
339361 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' ) ;
343363 } ) ;
344364 test ( 'close Promise is resolved with {currentData,instance} parameter after onClose event' , ( ) => {
345365 expect . assertions ( 6 ) ;
@@ -368,7 +388,19 @@ describe('close method : ', () => {
368388} ) ;
369389describe ( 'open method : ' , ( ) => {
370390 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+ } ) ;
372404 renderApp ( ) ;
373405 act ( ( ) => {
374406 instance . one ( 'onOpen' , onOpen ) . open ( {
@@ -385,9 +417,7 @@ describe('open method : ', () => {
385417 expect ( op . onOpen . mock . calls . length === 1 ) . toBe ( true ) ;
386418 expect ( op . onOpen . mock . calls [ 0 ] [ 0 ] ) . toEqual ( [ '3' , '4' ] ) ;
387419 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' ) ;
391421 } ) ;
392422 test ( 'open Promise is resolved with {currentData,instance} parameter after onOpen event' , ( ) => {
393423 expect . assertions ( 5 ) ;
@@ -498,15 +528,23 @@ describe('ready function : ', () => {
498528 } ) ;
499529 } ) ;
500530 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+ } ) ;
503542 renderApp ( ) ;
504543 ready ( onReady ) ;
505544 expect ( op . onLoad . mock . calls . length === 1 ) . toBe ( true ) ;
506545 expect ( op . onInit . mock . calls . length === 1 ) . toBe ( true ) ;
507546 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' ) ;
510548 expect ( op . onChange . mock . calls . length ) . toBe ( 0 ) ;
511549 } ) ;
512550} ) ;
@@ -685,6 +723,13 @@ describe('onFirstSelect callback : ', () => {
685723 expect ( op . onFirstSelect . mock . calls . length ) . toBe ( 0 ) ;
686724 } ) ;
687725 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+ } ) ;
688733 renderApp ( ) ;
689734 expect ( op . onFirstSelect . mock . calls . length ) . toBe ( 0 ) ;
690735 expect ( op . onSelect . mock . calls . length ) . toBe ( 0 ) ;
@@ -693,7 +738,7 @@ describe('onFirstSelect callback : ', () => {
693738 } ) ;
694739 expect ( op . onFirstSelect . mock . calls . length ) . toBe ( 1 ) ;
695740 expect ( op . onSelect . mock . calls . length ) . toBe ( 1 ) ;
696- expect ( op . onFirstSelect ) . toHaveBeenCalledBefore ( op . onSelect ) ;
741+ expect ( executionOrder . toString ( ) ) . toBe ( 'onFirstSelect, onSelect' ) ;
697742 act ( ( ) => {
698743 instance . select ( '1' ) ;
699744 } ) ;
0 commit comments