import {expectAssignable, expectType} from 'tsd' import {Agent, Dispatcher, MockAgent, MockClient, MockPool, setGlobalDispatcher} from '../..' import {MockInterceptor} from '../../types/mock-interceptor' import MockDispatch = MockInterceptor.MockDispatch; expectAssignable(new MockAgent()) expectAssignable(new MockAgent({})) { const mockAgent = new MockAgent() expectAssignable(setGlobalDispatcher(mockAgent)) // get expectAssignable(mockAgent.get('')) expectAssignable(mockAgent.get(new RegExp(''))) expectAssignable(mockAgent.get((origin) => { expectAssignable(origin) return true })) expectAssignable(mockAgent.get('')) // close expectAssignable>(mockAgent.close()) // deactivate expectAssignable(mockAgent.deactivate()) // activate expectAssignable(mockAgent.activate()) // enableNetConnect expectAssignable(mockAgent.enableNetConnect()) expectAssignable(mockAgent.enableNetConnect('')) expectAssignable(mockAgent.enableNetConnect(new RegExp(''))) expectAssignable(mockAgent.enableNetConnect((host) => { expectAssignable(host) return true })) // disableNetConnect expectAssignable(mockAgent.disableNetConnect()) // dispatch expectAssignable(mockAgent.dispatch({origin: '', path: '', method: 'GET'}, {})) // intercept expectAssignable((mockAgent.get('foo')).intercept({path: '', method: 'GET'})) } { const mockAgent = new MockAgent({connections: 1}) expectAssignable(setGlobalDispatcher(mockAgent)) expectAssignable(mockAgent.get('')) } { const agent = new Agent() const mockAgent = new MockAgent({agent}) expectAssignable(setGlobalDispatcher(mockAgent)) expectAssignable(mockAgent.get('')) } { interface PendingInterceptor extends MockDispatch { origin: string; } const agent = new MockAgent({agent: new Agent()}) expectType<() => PendingInterceptor[]>(agent.pendingInterceptors) expectType<(options?: { pendingInterceptorsFormatter?: { format(pendingInterceptors: readonly PendingInterceptor[]): string; } }) => void>(agent.assertNoPendingInterceptors) }