@@ -14,17 +14,23 @@ class TestEventEmitter extends GenericEventEmitter<AnyProviderEvent> {
1414 }
1515}
1616
17- // a little function to make sure we're at least waiting for the event loop
17+ // a little function to make sure we're at least waiting for the event loop
1818// to clear before we start making assertions
1919const wait = ( millis = 0 ) => {
20- return new Promise ( resolve => { setTimeout ( resolve , millis ) ; } ) ;
20+ return new Promise ( ( resolve ) => {
21+ setTimeout ( resolve , millis ) ;
22+ } ) ;
2123} ;
2224
2325describe ( 'GenericEventEmitter' , ( ) => {
26+ const emitter = new TestEventEmitter ( ) ;
27+
28+ afterEach ( ( ) => {
29+ emitter . removeAllHandlers ( ) ;
30+ } ) ;
31+
2432 describe ( 'addHandler should' , function ( ) {
2533 it ( 'attach handler for event type' , async function ( ) {
26- const emitter = new TestEventEmitter ( ) ;
27-
2834 const handler1 = jest . fn ( ) ;
2935 emitter . addHandler ( AllProviderEvents . Ready , handler1 ) ;
3036 emitter . emit ( AllProviderEvents . Ready ) ;
@@ -35,8 +41,6 @@ describe('GenericEventEmitter', () => {
3541 } ) ;
3642
3743 it ( 'attach several handlers for event type' , async function ( ) {
38- const emitter = new TestEventEmitter ( ) ;
39-
4044 const handler1 = jest . fn ( ) ;
4145 const handler2 = jest . fn ( ) ;
4246 const handler3 = jest . fn ( ) ;
@@ -64,7 +68,6 @@ describe('GenericEventEmitter', () => {
6468 debug : ( ) => done ( ) ,
6569 } ;
6670
67- const emitter = new TestEventEmitter ( ) ;
6871 emitter . setLogger ( logger ) ;
6972
7073 emitter . addHandler ( AllProviderEvents . Ready , async ( ) => {
@@ -74,8 +77,6 @@ describe('GenericEventEmitter', () => {
7477 } ) ;
7578
7679 it ( 'trigger handler for event type' , async function ( ) {
77- const emitter = new TestEventEmitter ( ) ;
78-
7980 const handler1 = jest . fn ( ) ;
8081 emitter . addHandler ( AllProviderEvents . Ready , handler1 ) ;
8182 emitter . emit ( AllProviderEvents . Ready ) ;
@@ -87,7 +88,6 @@ describe('GenericEventEmitter', () => {
8788
8889 it ( 'trigger handler for event type with event data' , async function ( ) {
8990 const event : ReadyEvent = { message : 'message' } ;
90- const emitter = new TestEventEmitter ( ) ;
9191
9292 const handler1 = jest . fn ( ) ;
9393 emitter . addHandler ( AllProviderEvents . Ready , handler1 ) ;
@@ -99,8 +99,6 @@ describe('GenericEventEmitter', () => {
9999 } ) ;
100100
101101 it ( 'trigger several handlers for event type' , async function ( ) {
102- const emitter = new TestEventEmitter ( ) ;
103-
104102 const handler1 = jest . fn ( ) ;
105103 const handler2 = jest . fn ( ) ;
106104 const handler3 = jest . fn ( ) ;
@@ -121,8 +119,6 @@ describe('GenericEventEmitter', () => {
121119
122120 describe ( 'removeHandler should' , ( ) => {
123121 it ( 'remove single handler' , async function ( ) {
124- const emitter = new TestEventEmitter ( ) ;
125-
126122 const handler1 = jest . fn ( ) ;
127123 emitter . addHandler ( AllProviderEvents . Ready , handler1 ) ;
128124
@@ -138,8 +134,6 @@ describe('GenericEventEmitter', () => {
138134
139135 describe ( 'removeAllHandlers should' , ( ) => {
140136 it ( 'remove all handlers for event type' , async function ( ) {
141- const emitter = new TestEventEmitter ( ) ;
142-
143137 const handler1 = jest . fn ( ) ;
144138 const handler2 = jest . fn ( ) ;
145139 emitter . addHandler ( AllProviderEvents . Ready , handler1 ) ;
@@ -156,8 +150,6 @@ describe('GenericEventEmitter', () => {
156150 } ) ;
157151
158152 it ( 'remove same handler when assigned to multiple events' , async function ( ) {
159- const emitter = new TestEventEmitter ( ) ;
160-
161153 const handler = jest . fn ( ) ;
162154 emitter . addHandler ( AllProviderEvents . Stale , handler ) ;
163155 emitter . addHandler ( AllProviderEvents . ContextChanged , handler ) ;
@@ -174,8 +166,6 @@ describe('GenericEventEmitter', () => {
174166 } ) ;
175167
176168 it ( 'allow addition/removal of duplicate handlers' , async function ( ) {
177- const emitter = new TestEventEmitter ( ) ;
178-
179169 const handler = jest . fn ( ) ;
180170 emitter . addHandler ( AllProviderEvents . Stale , handler ) ;
181171 emitter . addHandler ( AllProviderEvents . Stale , handler ) ;
@@ -191,8 +181,6 @@ describe('GenericEventEmitter', () => {
191181 } ) ;
192182
193183 it ( 'allow duplicate event handlers and call them' , async function ( ) {
194- const emitter = new TestEventEmitter ( ) ;
195-
196184 const handler = jest . fn ( ) ;
197185 emitter . addHandler ( AllProviderEvents . Stale , handler ) ;
198186 emitter . addHandler ( AllProviderEvents . Stale , handler ) ;
@@ -205,8 +193,6 @@ describe('GenericEventEmitter', () => {
205193 } ) ;
206194
207195 it ( 'remove all handlers only for event type' , async function ( ) {
208- const emitter = new TestEventEmitter ( ) ;
209-
210196 const handler1 = jest . fn ( ) ;
211197 const handler2 = jest . fn ( ) ;
212198 emitter . addHandler ( AllProviderEvents . Ready , handler1 ) ;
@@ -223,8 +209,6 @@ describe('GenericEventEmitter', () => {
223209 } ) ;
224210
225211 it ( 'remove all handlers if no event type is given' , async function ( ) {
226- const emitter = new TestEventEmitter ( ) ;
227-
228212 const handler1 = jest . fn ( ) ;
229213 const handler2 = jest . fn ( ) ;
230214 emitter . addHandler ( AllProviderEvents . Ready , handler1 ) ;
0 commit comments