From e7ba1ae083a09876f199e8fbde9a62ac8d6cf2a7 Mon Sep 17 00:00:00 2001 From: uzlopak Date: Sat, 24 Aug 2024 01:45:50 +0200 Subject: [PATCH] fix(types): MockAgent accepts ProxyAgent, EnvHttpProxyAgent and RetryAgent for agent option --- test/types/mock-agent.test-d.ts | 20 ++++++++++++++++++++ types/mock-agent.d.ts | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/test/types/mock-agent.test-d.ts b/test/types/mock-agent.test-d.ts index c1930db9edf..91962e4a8a0 100644 --- a/test/types/mock-agent.test-d.ts +++ b/test/types/mock-agent.test-d.ts @@ -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(new MockAgent()) @@ -75,3 +79,19 @@ expectAssignable(new MockAgent({})) } }) => void>(agent.assertNoPendingInterceptors) } + +// issue #3444 +// ProxyAgent, EnvHttpProxyAgent, RetryAgent should be assignable to the agent +// option of MockAgent + +expectType(new MockAgent({ + agent: new ProxyAgent({ + uri: 'http://localhost:3000' + }) +})) +expectType(new MockAgent({ + agent: new EnvHttpProxyAgent() +})) +expectType(new MockAgent({ + agent: new RetryAgent(new Agent()) +})) diff --git a/types/mock-agent.d.ts b/types/mock-agent.d.ts index 17c09386f3f..da40a43b744 100644 --- a/types/mock-agent.d.ts +++ b/types/mock-agent.d.ts @@ -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; } }