import sinon from 'sinon'; export async function testPrivateMethod any>( service: any, methodName: string, testFn: (method: T) => Promise | void, ): Promise { const proto = Object.getPrototypeOf(service); const originalMethod = proto[methodName]; const isStubbed = originalMethod && 'restore' in originalMethod; if (isStubbed) { (originalMethod as sinon.SinonStub).restore(); } const method = proto[methodName]; void testFn(method.bind(service)); if (isStubbed) { sinon.stub(proto, methodName).callsFake(originalMethod); } } export function createFreshServiceInstance(moduleExports: any, serviceName?: string): T { const ServiceClass = serviceName ? moduleExports[serviceName] : Object.values(moduleExports)[0]; return new ServiceClass(); }