@@ -469,10 +469,8 @@ describe('Integration', () => {
469469 expect ( handlers2 . onDestroy ) . toHaveBeenCalledTimes ( 1 ) ;
470470 } ) ;
471471
472- it ( 'should throw an error if contained store is used without container' , async ( ) => {
473- const rejectSpy = jest
474- . spyOn ( Promise , 'reject' )
475- . mockImplementation ( ( ) => { } ) ;
472+ it ( 'should throw an error if contained store is used without container' , ( ) => {
473+ const errorSpy = jest . spyOn ( console , 'error' ) . mockImplementation ( ( ) => { } ) ;
476474 const Store1 = createStore ( {
477475 name : 'one' ,
478476 initialState : { todos : [ ] , loading : false } ,
@@ -481,13 +479,11 @@ describe('Integration', () => {
481479 } ) ;
482480
483481 const Subscriber = createSubscriber ( Store1 ) ;
484- render ( < Subscriber > { ( ) => null } </ Subscriber > ) ;
485- await actTick ( ) ;
486482
487- expect ( rejectSpy ) . toHaveBeenCalled ( ) ;
488- const [ error ] = rejectSpy . mock . calls [ 0 ] ;
489- expect ( error ) . toEqual ( expect . any ( Error ) ) ;
490- expect ( error . message ) . toContain ( 'should be contained' ) ;
483+ expect ( ( ) => render ( < Subscriber > { ( ) => null } </ Subscriber > ) ) . toThrow (
484+ / s h o u l d b e c o n t a i n e d /
485+ ) ;
486+ errorSpy . mockRestore ( ) ;
491487 } ) ;
492488
493489 describe ( 'dispatchTo' , ( ) => {
@@ -514,107 +510,131 @@ describe('Integration', () => {
514510 } ,
515511 } ) ;
516512
517- const MainContainer = mainContainer ?? ( ( { children } ) => children ) ;
518- const OtherContainer = otherContainer ?? ( ( { children } ) => children ) ;
519513 const MainSubscriber = createSubscriber ( StoreMain ) ;
520514 const OtherSubscriber = createSubscriber ( StoreOther ) ;
521515 const mainSpy = jest . fn ( ) . mockReturnValue ( null ) ;
522516 const otherSpy = jest . fn ( ) . mockReturnValue ( null ) ;
523517
524- const App = ( { plus } ) => (
525- < MainContainer >
526- < OtherContainer plus = { plus } >
527- < MainSubscriber > { mainSpy } </ MainSubscriber >
528- < OtherSubscriber > { otherSpy } </ OtherSubscriber >
529- </ OtherContainer >
530- </ MainContainer >
518+ const Content = ( ) => (
519+ < >
520+ < MainSubscriber > { mainSpy } </ MainSubscriber >
521+ < OtherSubscriber > { otherSpy } </ OtherSubscriber >
522+ </ >
531523 ) ;
532524 return {
533- App ,
525+ Content ,
534526 StoreMain,
535527 mainReturn : ( n = 0 ) => mainSpy . mock . calls [ n ] ,
536528 otherReturn : ( n = 0 ) => otherSpy . mock . calls [ n ] ,
537529 } ;
538530 } ;
539531
540- it ( 'should allow dispatchTo global -> global' , async ( ) => {
541- const { App , mainReturn, otherReturn } = createTestElements ( {
532+ it ( 'should allow dispatchTo global -> global' , ( ) => {
533+ const { Content , mainReturn, otherReturn } = createTestElements ( {
542534 mainContainer : null ,
543535 otherContainer : null ,
544536 } ) ;
545537
546- render ( < App /> ) ;
538+ render ( < Content /> ) ;
547539 const [ , mainActions ] = mainReturn ( 0 ) ;
548540 act ( ( ) => mainActions . setOther ( 1 ) ) ;
549541
550542 expect ( otherReturn ( 1 ) ) . toEqual ( [ { count : 1 } , expect . any ( Object ) ] ) ;
551543 } ) ;
552544
553- it ( 'should allow dispatchTo contained -> contained' , async ( ) => {
545+ it ( 'should allow dispatchTo contained -> contained' , ( ) => {
554546 const SharedContainer = createContainer ( ) ;
555- const { App , mainReturn, otherReturn } = createTestElements ( {
547+ const { Content , mainReturn, otherReturn } = createTestElements ( {
556548 mainContainer : SharedContainer ,
557549 otherContainer : SharedContainer ,
558550 } ) ;
559551
560- render ( < App /> ) ;
552+ render (
553+ < SharedContainer >
554+ < Content />
555+ </ SharedContainer >
556+ ) ;
561557 const [ , mainActions ] = mainReturn ( 0 ) ;
562558 act ( ( ) => mainActions . setOther ( 1 ) ) ;
563559
564560 expect ( otherReturn ( 1 ) ) . toEqual ( [ { count : 1 } , expect . any ( Object ) ] ) ;
565561 } ) ;
566562
567- it ( 'should error when dispatchTo contained -> global' , ( ) => {
568- const { App, mainReturn } = createTestElements ( {
569- mainContainer : createContainer ( ) ,
563+ it ( 'should allow dispatchTo contained -> global' , ( ) => {
564+ const MainContainer = createContainer ( ) ;
565+ const { Content, mainReturn, otherReturn } = createTestElements ( {
566+ mainContainer : MainContainer ,
570567 otherContainer : null ,
571568 } ) ;
572569
573- render ( < App /> ) ;
570+ render (
571+ < MainContainer >
572+ < Content />
573+ </ MainContainer >
574+ ) ;
574575 const [ , mainActions ] = mainReturn ( 0 ) ;
576+ act ( ( ) => mainActions . setOther ( 1 ) ) ;
575577
576- expect ( ( ) => mainActions . setOther ( 1 ) ) . toThrow ( / I l l e g a l / ) ;
578+ expect ( otherReturn ( 1 ) ) . toEqual ( [ { count : 1 } , expect . any ( Object ) ] ) ;
577579 } ) ;
578580
579- it ( 'should error when dispatchTo global -> contained' , async ( ) => {
580- const { App, mainReturn } = createTestElements ( {
581- mainContainer : createContainer ( ) ,
582- otherContainer : null ,
581+ it ( 'should allow dispatchTo global -> contained if properly contained' , ( ) => {
582+ const OtherContainer = createContainer ( { displayName : 'OtherContainer' } ) ;
583+ const { Content, mainReturn, otherReturn } = createTestElements ( {
584+ mainContainer : null ,
585+ otherContainer : OtherContainer ,
583586 } ) ;
584587
585- render ( < App /> ) ;
588+ render (
589+ < OtherContainer >
590+ < Content />
591+ </ OtherContainer >
592+ ) ;
586593 const [ , mainActions ] = mainReturn ( 0 ) ;
594+ act ( ( ) => mainActions . setOther ( 1 ) ) ;
587595
588- expect ( ( ) => mainActions . setOther ( 1 ) ) . toThrow ( / I l l e g a l / ) ;
596+ expect ( otherReturn ( 1 ) ) . toEqual ( [ { count : 1 } , expect . any ( Object ) ] ) ;
589597 } ) ;
590598
591- it ( 'should error when dispatchTo contained -> other contained' , async ( ) => {
592- const { App, mainReturn } = createTestElements ( {
593- mainContainer : createContainer ( ) ,
594- otherContainer : createContainer ( ) ,
599+ it ( 'should allow dispatchTo contained -> other contained' , async ( ) => {
600+ const MainContainer = createContainer ( ) ;
601+ const OtherContainer = createContainer ( ) ;
602+
603+ const { Content, mainReturn, otherReturn } = createTestElements ( {
604+ mainContainer : MainContainer ,
605+ otherContainer : OtherContainer ,
595606 } ) ;
596607
597- render ( < App /> ) ;
608+ render (
609+ < OtherContainer >
610+ < MainContainer >
611+ < Content />
612+ </ MainContainer >
613+ </ OtherContainer >
614+ ) ;
598615 const [ , mainActions ] = mainReturn ( 0 ) ;
616+ act ( ( ) => mainActions . setOther ( 1 ) ) ;
599617
600- expect ( ( ) => mainActions . setOther ( 1 ) ) . toThrow ( / I l l e g a l / ) ;
618+ expect ( otherReturn ( 1 ) ) . toEqual ( [ { count : 1 } , expect . any ( Object ) ] ) ;
601619 } ) ;
602620
603- it ( 'should error when dispatchTo override -> contained' , async ( ) => {
604- const { App, StoreMain, mainReturn } = createTestElements ( {
605- mainContainer : null ,
606- otherContainer : null ,
607- } ) ;
621+ it ( 'should allow dispatchTo override -> contained' , async ( ) => {
622+ const { Content, StoreMain, mainReturn, otherReturn } =
623+ createTestElements ( {
624+ mainContainer : null ,
625+ otherContainer : null ,
626+ } ) ;
608627 const OverrideContainer = createContainer ( StoreMain ) ;
609628
610629 render (
611630 < OverrideContainer >
612- < App />
631+ < Content />
613632 </ OverrideContainer >
614633 ) ;
615634 const [ , mainActions ] = mainReturn ( 0 ) ;
635+ act ( ( ) => mainActions . setOther ( 1 ) ) ;
616636
617- expect ( ( ) => mainActions . setOther ( 1 ) ) . toThrow ( / I l l e g a l / ) ;
637+ expect ( otherReturn ( 1 ) ) . toEqual ( [ { count : 1 } , expect . any ( Object ) ] ) ;
618638 } ) ;
619639 } ) ;
620640} ) ;
0 commit comments