@@ -486,6 +486,84 @@ it('emits-only transitions should emit events', () => {
486486 expect ( spy ) . toHaveBeenCalledTimes ( 1 ) ;
487487} ) ;
488488
489+ it ( 'wildcard listener receives all emitted events' , ( ) => {
490+ const spy = vi . fn ( ) ;
491+ const store = createStore ( {
492+ context : { count : 0 } ,
493+ emits : {
494+ increased : ( _ : { upBy : number } ) => { } ,
495+ decreased : ( _ : { downBy : number } ) => { }
496+ } ,
497+ on : {
498+ inc : ( ctx , _ , enq ) => {
499+ enq . emit . increased ( { upBy : 1 } ) ;
500+ return { ...ctx , count : ctx . count + 1 } ;
501+ } ,
502+ dec : ( ctx , _ , enq ) => {
503+ enq . emit . decreased ( { downBy : 1 } ) ;
504+ return { ...ctx , count : ctx . count - 1 } ;
505+ }
506+ }
507+ } ) ;
508+
509+ store . on ( '*' , spy ) ;
510+
511+ store . trigger . inc ( ) ;
512+ expect ( spy ) . toHaveBeenCalledWith ( { type : 'increased' , upBy : 1 } ) ;
513+
514+ store . trigger . dec ( ) ;
515+ expect ( spy ) . toHaveBeenCalledWith ( { type : 'decreased' , downBy : 1 } ) ;
516+
517+ expect ( spy ) . toHaveBeenCalledTimes ( 2 ) ;
518+ } ) ;
519+
520+ it ( 'wildcard listener can be unsubscribed' , ( ) => {
521+ const spy = vi . fn ( ) ;
522+ const store = createStore ( {
523+ context : { count : 0 } ,
524+ emits : {
525+ increased : ( _ : { upBy : number } ) => { }
526+ } ,
527+ on : {
528+ inc : ( ctx , _ , enq ) => {
529+ enq . emit . increased ( { upBy : 1 } ) ;
530+ return { ...ctx , count : ctx . count + 1 } ;
531+ }
532+ }
533+ } ) ;
534+
535+ const sub = store . on ( '*' , spy ) ;
536+ store . trigger . inc ( ) ;
537+ expect ( spy ) . toHaveBeenCalledTimes ( 1 ) ;
538+
539+ sub . unsubscribe ( ) ;
540+ store . trigger . inc ( ) ;
541+ expect ( spy ) . toHaveBeenCalledTimes ( 1 ) ;
542+ } ) ;
543+
544+ it ( 'wildcard listener is called after specific listener' , ( ) => {
545+ const order : string [ ] = [ ] ;
546+ const store = createStore ( {
547+ context : { count : 0 } ,
548+ emits : {
549+ increased : ( _ : { upBy : number } ) => { }
550+ } ,
551+ on : {
552+ inc : ( ctx , _ , enq ) => {
553+ enq . emit . increased ( { upBy : 1 } ) ;
554+ return { ...ctx , count : ctx . count + 1 } ;
555+ }
556+ }
557+ } ) ;
558+
559+ store . on ( 'increased' , ( ) => order . push ( 'specific' ) ) ;
560+ store . on ( '*' , ( ) => order . push ( 'wildcard' ) ) ;
561+
562+ store . trigger . inc ( ) ;
563+
564+ expect ( order ) . toEqual ( [ 'specific' , 'wildcard' ] ) ;
565+ } ) ;
566+
489567it ( 'async effects can be enqueued' , async ( ) => {
490568 const store = createStore ( {
491569 context : {
0 commit comments