1- import { subscribe , publish , messages } from "../Event.js" ;
1+ import { messages , publish , subscribe } from "../Event.js" ;
22
33describe ( "react-event" , ( ) => {
44 it ( "subscribes and publishes events" , ( done ) => {
5- subscribe ( "TEST_EVENT" , ( result ) => {
5+ subscribe ( "REACT-EVENT_TEST" , " TEST_EVENT", ( result ) => {
66 expect ( result ) . toMatchObject ( { number : 10 , string : "blue" } ) ;
77 } ) ;
88
9- subscribe ( "TEST_EVENT" , ( result ) => {
9+ subscribe ( "REACT-EVENT_TEST" , " TEST_EVENT", ( result ) => {
1010 expect ( result ) . toMatchObject ( { number : 10 , string : "blue" } ) ;
1111 done ( ) ;
1212 } ) ;
1313
14- publish ( "TEST_EVENT" , { number : 10 , string : "blue" } ) ;
14+ publish ( "REACT-EVENT_TEST" , " TEST_EVENT", { number : 10 , string : "blue" } ) ;
1515 } ) ;
1616
1717 it ( "publishes and subscribes events" , ( done ) => {
18- publish ( "TEST_EVENT" , { number : 10 , string : "blue" } ) ;
18+ publish ( "REACT-EVENT_TEST" , " TEST_EVENT", { number : 10 , string : "blue" } ) ;
1919
20- subscribe ( "TEST_EVENT" , ( result ) => {
20+ subscribe ( "REACT-EVENT_TEST" , " TEST_EVENT", ( result ) => {
2121 expect ( result ) . toMatchObject ( { number : 10 , string : "blue" } ) ;
2222 done ( ) ;
2323 } ) ;
@@ -33,63 +33,76 @@ describe("react-event", () => {
3333 }
3434 } ;
3535
36- subscribe ( "MULTI_SUB_EVENT" , ( result ) => {
36+ subscribe ( "REACT-EVENT_TEST" , " MULTI_SUB_EVENT", ( result ) => {
3737 expect ( result ) . toMatchObject ( { data : "shared" } ) ;
3838 receivedByFirstSubscriber = true ;
3939 checkDone ( ) ;
4040 } ) ;
4141
42- subscribe ( "MULTI_SUB_EVENT" , ( result ) => {
42+ subscribe ( "REACT-EVENT_TEST" , " MULTI_SUB_EVENT", ( result ) => {
4343 expect ( result ) . toMatchObject ( { data : "shared" } ) ;
4444 receivedBySecondSubscriber = true ;
4545 checkDone ( ) ;
4646 } ) ;
4747
48- publish ( "MULTI_SUB_EVENT" , { data : "shared" } ) ;
48+ publish ( "REACT-EVENT_TEST" , " MULTI_SUB_EVENT", { data : "shared" } ) ;
4949 } ) ;
5050
5151 it ( "handles events with no subscribers without errors" , ( ) => {
5252 expect ( ( ) =>
53- publish ( "NO_SUBSCRIBER_EVENT" , { data : "none" } )
53+ publish ( "REACT-EVENT_TEST" , " NO_SUBSCRIBER_EVENT", { data : "none" } )
5454 ) . not . toThrow ( ) ;
5555 } ) ;
5656
5757 it ( "registers the last published event to map" , ( ) => {
58- publish ( "LAST_EVENT" , { data : "test payload" } ) ;
58+ publish ( "REACT-EVENT_TEST" , " LAST_EVENT", { data : "test payload" } ) ;
5959
60- const lastPublishedEvent = messages . get ( "LAST_EVENT" ) ;
60+ const lastPublishedEvent = messages . get ( "REACT-EVENT_TEST. LAST_EVENT" ) ;
6161 expect ( lastPublishedEvent ) . toEqual ( { data : "test payload" } ) ;
6262 } ) ;
6363
6464 it ( "returns registry in callback" , ( done ) => {
65- publish ( "CALLBACK_REGISTRY_EVENT" , { data : "test payload" } ) ;
66-
67- subscribe ( "CALLBACK_REGISTRY_EVENT" , ( result , registry ) => {
68- expect ( result ) . toMatchObject ( { data : "test payload" } ) ;
69- expect ( registry ) . toMatchObject ( {
70- id : expect . any ( String ) ,
71- type : "CALLBACK_REGISTRY_EVENT" ,
72- callback : expect . any ( Function ) ,
73- unsubscribe : expect . any ( Function ) ,
74- } ) ;
75-
76- registry . unsubscribe ( ) ;
65+ publish ( "REACT-EVENT_TEST" , "CALLBACK_REGISTRY_EVENT" , {
66+ data : "test payload" ,
7767 } ) ;
7868
79- subscribe ( "CALLBACK_REGISTRY_EVENT_2" , ( result , registry ) => {
80- expect ( result ) . toMatchObject ( { data : "test payload 2" } ) ;
81- expect ( registry ) . toMatchObject ( {
82- id : expect . any ( String ) ,
83- type : "CALLBACK_REGISTRY_EVENT_2" ,
84- callback : expect . any ( Function ) ,
85- unsubscribe : expect . any ( Function ) ,
86- } ) ;
69+ subscribe (
70+ "REACT-EVENT_TEST" ,
71+ "CALLBACK_REGISTRY_EVENT" ,
72+ ( result , registry ) => {
73+ expect ( result ) . toMatchObject ( { data : "test payload" } ) ;
74+ expect ( registry ) . toMatchObject ( {
75+ id : expect . any ( String ) ,
76+ type : "REACT-EVENT_TEST.CALLBACK_REGISTRY_EVENT" ,
77+ callback : expect . any ( Function ) ,
78+ unsubscribe : expect . any ( Function ) ,
79+ } ) ;
80+
81+ registry . unsubscribe ( ) ;
82+ }
83+ ) ;
84+
85+ subscribe (
86+ "REACT-EVENT_TEST" ,
87+ "CALLBACK_REGISTRY_EVENT_2" ,
88+ ( result , registry ) => {
89+ expect ( result ) . toMatchObject ( { data : "test payload 2" } ) ;
90+ expect ( registry ) . toMatchObject ( {
91+ id : expect . any ( String ) ,
92+ type : "REACT-EVENT_TEST.CALLBACK_REGISTRY_EVENT_2" ,
93+ callback : expect . any ( Function ) ,
94+ unsubscribe : expect . any ( Function ) ,
95+ } ) ;
96+
97+ registry . unsubscribe ( ) ;
8798
88- registry . unsubscribe ( ) ;
99+ done ( ) ;
100+ }
101+ ) ;
89102
90- done ( ) ;
103+ publish ( "REACT-EVENT_TEST" , "CALLBACK_REGISTRY_EVENT_2" , {
104+ data : "test payload 2" ,
91105 } ) ;
92-
93- publish ( "CALLBACK_REGISTRY_EVENT_2" , { data : "test payload 2" } ) ;
94106 } ) ;
95107} ) ;
108+
0 commit comments