Skip to content
Open
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
10 changes: 2 additions & 8 deletions test/types/mock-agent.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ 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())
expectAssignable<MockAgent>(new MockAgent({}))

Expand Down Expand Up @@ -67,15 +65,11 @@ expectAssignable<MockAgent>(new MockAgent({}))
}

{
interface PendingInterceptor extends MockDispatch {
origin: string;
}

const agent = new MockAgent({ agent: new Agent() })
expectType<() => PendingInterceptor[]>(agent.pendingInterceptors)
expectType<() => MockAgent.PendingInterceptor[]>(agent.pendingInterceptors)
expectType<(options?: {
pendingInterceptorsFormatter?: {
format(pendingInterceptors: readonly PendingInterceptor[]): string;
format(pendingInterceptors: readonly MockAgent.PendingInterceptor[]): string;
}
}) => void>(agent.assertNoPendingInterceptors)
}
Expand Down
20 changes: 10 additions & 10 deletions types/mock-agent.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ import { MockCallHistory } from './mock-call-history'

export default MockAgent

interface PendingInterceptor extends MockDispatch {
origin: string;
}

/** A mocked Agent class that implements the Agent API. It allows one to intercept HTTP requests made through undici and return mocked responses instead. */
declare class MockAgent<TMockAgentOptions extends MockAgent.Options = MockAgent.Options> extends Dispatcher {
constructor (options?: TMockAgentOptions)
Expand Down Expand Up @@ -40,17 +36,21 @@ declare class MockAgent<TMockAgentOptions extends MockAgent.Options = MockAgent.
enableCallHistory (): this
/** Disable call history. Any subsequence calls will then not be registered. */
disableCallHistory (): this
pendingInterceptors (): PendingInterceptor[]
pendingInterceptors (): MockAgent.PendingInterceptor[]
assertNoPendingInterceptors (options?: {
pendingInterceptorsFormatter?: PendingInterceptorsFormatter;
pendingInterceptorsFormatter?: MockAgent.PendingInterceptorsFormatter;
}): void
}

interface PendingInterceptorsFormatter {
format(pendingInterceptors: readonly PendingInterceptor[]): string;
}

declare namespace MockAgent {
export interface PendingInterceptor extends MockDispatch {
origin: string;
}

export interface PendingInterceptorsFormatter {
format(pendingInterceptors: readonly PendingInterceptor[]): string;
}

/** MockAgent options. */
export interface Options extends Agent.Options {
/** A custom agent to be encapsulated by the MockAgent. */
Expand Down