import MoonClient from "../src/moonClient" ; import { ClientInstance , ILink } from "../src/utils" ; export interface MockedClientConfig { baseURL : string ; } export class MockedClient implements ClientInstance { public get : ( ) => Promise < any > ; public post : ( ) => Promise < any > ; public delete : ( ) => Promise < any > ; public put : ( ) => Promise < any > ; public patch : ( ) => Promise < any > ; public config : MockedClientConfig ; constructor ( config ) { this . config = config ; this . get = jest . fn ( ) ; this . post = jest . fn ( ) ; this . delete = jest . fn ( ) ; this . put = jest . fn ( ) ; this . patch = jest . fn ( ) ; } } export const createClientFactory = ( Factory ) => ( config ) : MockedClient => { return new Factory ( config ) ; } ; export function getMockedMoonClient ( links , clientFactory = createClientFactory ( MockedClient ) ) { return new MoonClient ( links , clientFactory ) ; } export function getMockedClientFactory ( { get = jest . fn ( ) , post = jest . fn ( ) } ) { class CustomClient extends MockedClient { constructor ( config ) { super ( config ) ; this . get = get ; this . post = post ; } } return createClientFactory ( CustomClient ) ; }