@@ -159,7 +159,7 @@ class MockAgent extends Dispatcher {
159159 }
160160
161161 [ kMockAgentSet ] ( origin , dispatcher ) {
162- this [ kClients ] . set ( origin , dispatcher )
162+ this [ kClients ] . set ( origin , { count : 0 , dispatcher } )
163163 }
164164
165165 [ kFactory ] ( origin ) {
@@ -171,9 +171,9 @@ class MockAgent extends Dispatcher {
171171
172172 [ kMockAgentGet ] ( origin ) {
173173 // First check if we can immediately find it
174- const client = this [ kClients ] . get ( origin )
175- if ( client ) {
176- return client
174+ const result = this [ kClients ] . get ( origin )
175+ if ( result ?. dispatcher ) {
176+ return result . dispatcher
177177 }
178178
179179 // If the origin is not a string create a dummy parent pool and return to user
@@ -184,11 +184,11 @@ class MockAgent extends Dispatcher {
184184 }
185185
186186 // If we match, create a pool and assign the same dispatches
187- for ( const [ keyMatcher , nonExplicitDispatcher ] of Array . from ( this [ kClients ] ) ) {
188- if ( nonExplicitDispatcher && typeof keyMatcher !== 'string' && matchValue ( keyMatcher , origin ) ) {
187+ for ( const [ keyMatcher , result ] of Array . from ( this [ kClients ] ) ) {
188+ if ( result && typeof keyMatcher !== 'string' && matchValue ( keyMatcher , origin ) ) {
189189 const dispatcher = this [ kFactory ] ( origin )
190190 this [ kMockAgentSet ] ( origin , dispatcher )
191- dispatcher [ kDispatches ] = nonExplicitDispatcher [ kDispatches ]
191+ dispatcher [ kDispatches ] = result . dispatcher [ kDispatches ]
192192 return dispatcher
193193 }
194194 }
@@ -202,7 +202,7 @@ class MockAgent extends Dispatcher {
202202 const mockAgentClients = this [ kClients ]
203203
204204 return Array . from ( mockAgentClients . entries ( ) )
205- . flatMap ( ( [ origin , scope ] ) => scope [ kDispatches ] . map ( dispatch => ( { ...dispatch , origin } ) ) )
205+ . flatMap ( ( [ origin , result ] ) => result . dispatcher [ kDispatches ] . map ( dispatch => ( { ...dispatch , origin } ) ) )
206206 . filter ( ( { pending } ) => pending )
207207 }
208208
0 commit comments