File tree Expand file tree Collapse file tree 2 files changed +12
-0
lines changed
Expand file tree Collapse file tree 2 files changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -31,6 +31,10 @@ function typeColor(type) {
3131}
3232
3333const subscribe = ( ...args ) => {
34+ if ( args . length < 2 ) {
35+ throw new Error ( "subscribe requires at least 2 arguments" ) ;
36+ }
37+
3438 const callback = args . pop ( ) ;
3539 const type = args . join ( "." ) ;
3640 const id = uuid ( ) ;
@@ -69,6 +73,10 @@ const subscribe = (...args) => {
6973} ;
7074
7175const publish = ( ...args ) => {
76+ if ( args . length < 2 ) {
77+ throw new Error ( "publish requires at least 2 arguments" ) ;
78+ }
79+
7280 const payload = args . pop ( ) ;
7381 const type = args . join ( "." ) ;
7482
Original file line number Diff line number Diff line change 11import { subscribe , publish , messages } from "../Event.js" ;
22
33describe ( "react-event" , ( ) => {
4+ it ( "accepts type and payload" , ( ) => {
5+ expect ( ( ) => publish ( "TEST_EVENT" ) ) . toThrow ( ) ;
6+ } ) ;
7+
48 it ( "subscribes and publishes events" , ( done ) => {
59 subscribe ( "TEST_EVENT" , ( result ) => {
610 expect ( result ) . toMatchObject ( { number : 10 , string : "blue" } ) ;
You can’t perform that action at this time.
0 commit comments