Skip to content

Commit

Permalink
fix(types): MockAgent accepts ProxyAgent, EnvHttpProxyAgent and Retry…
Browse files Browse the repository at this point in the history
…Agent for agent option (#3497)
  • Loading branch information
Uzlopak authored Aug 24, 2024
1 parent a3761f9 commit 91230e8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
20 changes: 20 additions & 0 deletions test/types/mock-agent.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { expectAssignable, expectType } from 'tsd'
import { Agent, Dispatcher, MockAgent, MockClient, MockPool, setGlobalDispatcher } from '../..'
import { MockInterceptor } from '../../types/mock-interceptor'
import ProxyAgent from '../../types/proxy-agent'
import EnvHttpProxyAgent from '../../types/env-http-proxy-agent'
import RetryAgent from '../../types/retry-agent'

import MockDispatch = MockInterceptor.MockDispatch

expectAssignable<MockAgent>(new MockAgent())
Expand Down Expand Up @@ -75,3 +79,19 @@ expectAssignable<MockAgent>(new MockAgent({}))
}
}) => void>(agent.assertNoPendingInterceptors)
}

// issue #3444
// ProxyAgent, EnvHttpProxyAgent, RetryAgent should be assignable to the agent
// option of MockAgent

expectType<MockAgent>(new MockAgent({
agent: new ProxyAgent({
uri: 'http://localhost:3000'
})
}))
expectType<MockAgent>(new MockAgent({
agent: new EnvHttpProxyAgent()
}))
expectType<MockAgent>(new MockAgent({
agent: new RetryAgent(new Agent())
}))
2 changes: 1 addition & 1 deletion types/mock-agent.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ declare namespace MockAgent {
/** MockAgent options. */
export interface Options extends Agent.Options {
/** A custom agent to be encapsulated by the MockAgent. */
agent?: Agent;
agent?: Dispatcher;
}
}

0 comments on commit 91230e8

Please sign in to comment.