Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(types): MockAgent accepts ProxyAgent, EnvHttpProxyAgent and RetryAgent for agent option #3497

Merged
merged 1 commit into from
Aug 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}
Loading