File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed
Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -65,6 +65,15 @@ describe('mitt#', () => {
6565 inst . on ( eventType , foo ) ;
6666 expect ( events . get ( eventType ) ) . to . deep . equal ( [ foo ] ) ;
6767 } ) ;
68+
69+ // Adding the same listener multiple times should register it multiple times.
70+ // See https://nodejs.org/api/events.html#events_emitter_on_eventname_listener
71+ it ( 'should add duplicate listeners' , ( ) => {
72+ const foo = ( ) => { } ;
73+ inst . on ( 'foo' , foo ) ;
74+ inst . on ( 'foo' , foo ) ;
75+ expect ( events . get ( 'foo' ) ) . to . deep . equal ( [ foo , foo ] ) ;
76+ } ) ;
6877 } ) ;
6978
7079 describe ( 'off()' , ( ) => {
@@ -98,6 +107,16 @@ describe('mitt#', () => {
98107 expect ( events . has ( 'bar' ) ) . to . equal ( false ) ;
99108 expect ( events . get ( 'baz:bat!' ) ) . to . have . lengthOf ( 1 ) ;
100109 } ) ;
110+
111+ it ( 'should remove only the first matching listener' , ( ) => {
112+ const foo = ( ) => { } ;
113+ inst . on ( 'foo' , foo ) ;
114+ inst . on ( 'foo' , foo ) ;
115+ inst . off ( 'foo' , foo ) ;
116+ expect ( events . get ( 'foo' ) ) . to . deep . equal ( [ foo ] ) ;
117+ inst . off ( 'foo' , foo ) ;
118+ expect ( events . get ( 'foo' ) ) . to . deep . equal ( [ ] ) ;
119+ } ) ;
101120 } ) ;
102121
103122 describe ( 'emit()' , ( ) => {
You can’t perform that action at this time.
0 commit comments