@fetch-mock/vitest
Version:
Vitest wrapper for fetch-mock
48 lines (47 loc) • 2.25 kB
TypeScript
import type { CallHistoryFilter, FetchMock, RouteName, UserRouteConfig } from 'fetch-mock';
import type { SyncExpectationResult } from 'expect';
export type HumanVerbs = 'Got' | 'Posted' | 'Put' | 'Deleted' | 'FetchedHead' | 'Patched' | 'Fetched';
export type ToHaveFunc<R> = (filter?: CallHistoryFilter, options?: UserRouteConfig) => R;
export type ToHaveNthFunc<R> = (n: number, filter?: CallHistoryFilter, options?: UserRouteConfig) => R;
export type ToHaveTimesFunc<R> = (times: number, filter?: CallHistoryFilter, options?: UserRouteConfig) => R;
export type ToBeDoneFunc<R> = (routes?: RouteName | RouteName[]) => R;
export type FetchMockMatchers<R = void> = {
toHaveFetched: ToHaveFunc<R>;
toHaveLastFetched: ToHaveFunc<R>;
toHaveFetchedTimes: ToHaveTimesFunc<R>;
toHaveNthFetched: ToHaveNthFunc<R>;
toHaveGot: ToHaveFunc<R>;
toHaveLastGot: ToHaveFunc<R>;
toHaveGotTimes: ToHaveTimesFunc<R>;
toHaveNthGot: ToHaveNthFunc<R>;
toHavePosted: ToHaveFunc<R>;
toHaveLastPosted: ToHaveFunc<R>;
toHavePostedTimes: ToHaveTimesFunc<R>;
toHaveNthPosted: ToHaveNthFunc<R>;
toHavePut: ToHaveFunc<R>;
toHaveLastPut: ToHaveFunc<R>;
toHavePutTimes: ToHaveTimesFunc<R>;
toHaveNthPut: ToHaveNthFunc<R>;
toHaveDeleted: ToHaveFunc<R>;
toHaveLastDeleted: ToHaveFunc<R>;
toHaveDeletedTimes: ToHaveTimesFunc<R>;
toHaveNthDeleted: ToHaveNthFunc<R>;
toHaveFetchedHead: ToHaveFunc<R>;
toHaveLastFetchedHead: ToHaveFunc<R>;
toHaveFetchedHeadTimes: ToHaveTimesFunc<R>;
toHaveNthFetchedHead: ToHaveNthFunc<R>;
toHavePatched: ToHaveFunc<R>;
toHaveLastPatched: ToHaveFunc<R>;
toHavePatchedTimes: ToHaveTimesFunc<R>;
toHaveNthPatched: ToHaveNthFunc<R>;
toBeDone: ToBeDoneFunc<R>;
};
export type PatchedFetch = {
fetchMock: FetchMock;
};
type RawMatcher<T extends (...args: any[]) => any> = (input: PatchedFetch | FetchMock, ...args: Parameters<T>) => ReturnType<T>;
export type RawFetchMockMatchers = {
[k in keyof FetchMockMatchers<SyncExpectationResult>]: RawMatcher<FetchMockMatchers<SyncExpectationResult>[k]>;
};
export type HumanVerbMethodNames<M extends HumanVerbs> = `toHave${M}` | `toHaveLast${M}` | `toHave${M}Times` | `toHaveNth${M}`;
export {};