|
| 1 | +import type { CallHistoryFilter, FetchMock, UserRouteConfig } from 'fetch-mock'; |
| 2 | +import type { SyncExpectationResult } from 'expect'; |
| 3 | + |
| 4 | +export type HumanVerbs = |
| 5 | + | 'Got' |
| 6 | + | 'Posted' |
| 7 | + | 'Put' |
| 8 | + | 'Deleted' |
| 9 | + | 'FetchedHead' |
| 10 | + | 'Patched' |
| 11 | + | 'Fetched'; |
| 12 | + |
| 13 | +/** |
| 14 | + * Verify that a particular call for the HTTP method implied in the function name |
| 15 | + * has occurred |
| 16 | + */ |
| 17 | +export type ToHaveFunc = ( |
| 18 | + filter: CallHistoryFilter, |
| 19 | + options: UserRouteConfig, |
| 20 | +) => SyncExpectationResult; |
| 21 | + |
| 22 | +/** |
| 23 | + * Verify that a particular Nth call for the HTTP method implied in the function name |
| 24 | + * has occurred |
| 25 | + */ |
| 26 | +export type ToHaveNthFunc = ( |
| 27 | + n: number, |
| 28 | + filter: CallHistoryFilter, |
| 29 | + options: UserRouteConfig, |
| 30 | +) => SyncExpectationResult; |
| 31 | + |
| 32 | +/** |
| 33 | + * Verify that a particular call for the HTTP method implied in the function name |
| 34 | + * has been made N times |
| 35 | + */ |
| 36 | +export type ToHaveTimesFunc = ( |
| 37 | + times: number, |
| 38 | + filter: CallHistoryFilter, |
| 39 | + options: UserRouteConfig, |
| 40 | +) => SyncExpectationResult; |
| 41 | + |
| 42 | +export type FetchMockMatchers = { |
| 43 | + toHaveFetched: ToHaveFunc; |
| 44 | + toHaveLastFetched: ToHaveFunc; |
| 45 | + toHaveFetchedTimes: ToHaveTimesFunc; |
| 46 | + toHaveNthFetched: ToHaveNthFunc; |
| 47 | + toHaveGot: ToHaveFunc; |
| 48 | + toHaveLastGot: ToHaveFunc; |
| 49 | + toHaveGotTimes: ToHaveTimesFunc; |
| 50 | + toHaveNthGot: ToHaveNthFunc; |
| 51 | + toHavePosted: ToHaveFunc; |
| 52 | + toHaveLastPosted: ToHaveFunc; |
| 53 | + toHavePostedTimes: ToHaveTimesFunc; |
| 54 | + toHaveNthPosted: ToHaveNthFunc; |
| 55 | + toHavePut: ToHaveFunc; |
| 56 | + toHaveLastPut: ToHaveFunc; |
| 57 | + toHavePutTimes: ToHaveTimesFunc; |
| 58 | + toHaveNthPut: ToHaveNthFunc; |
| 59 | + toHaveDeleted: ToHaveFunc; |
| 60 | + toHaveLastDeleted: ToHaveFunc; |
| 61 | + toHaveDeletedTimes: ToHaveTimesFunc; |
| 62 | + toHaveNthDeleted: ToHaveNthFunc; |
| 63 | + toHaveFetchedHead: ToHaveFunc; |
| 64 | + toHaveLastFetchedHead: ToHaveFunc; |
| 65 | + toHaveFetchedHeadTimes: ToHaveTimesFunc; |
| 66 | + toHaveNthFetchedHead: ToHaveNthFunc; |
| 67 | + toHavePatched: ToHaveFunc; |
| 68 | + toHaveLastPatched: ToHaveFunc; |
| 69 | + toHavePatchedTimes: ToHaveTimesFunc; |
| 70 | + toHaveNthPatched: ToHaveNthFunc; |
| 71 | +}; |
| 72 | + |
| 73 | +// types for use doing some intermediate type checking in extensions to make sure things don't get out of sync |
| 74 | +/** |
| 75 | + * This type allows us to take the Matcher type and creat another one |
| 76 | + */ |
| 77 | +// eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 78 | +type RawMatcher<T extends (...args: any[]) => any> = ( |
| 79 | + input: { fetchMock: FetchMock }, |
| 80 | + ...args: Parameters<T> |
| 81 | +) => ReturnType<T>; |
| 82 | + |
| 83 | +export type RawFetchMockMatchers = { |
| 84 | + [k in keyof FetchMockMatchers]: RawMatcher<FetchMockMatchers[k]>; |
| 85 | +}; |
| 86 | + |
| 87 | +export type HumanVerbMethodNames<M extends HumanVerbs> = |
| 88 | + | `toHave${M}` |
| 89 | + | `toHaveLast${M}` |
| 90 | + | `toHave${M}Times` |
| 91 | + | `toHaveNth${M}`; |
0 commit comments