He pasado mucho tiempo tratando de tener una comprensión razonable de este asunto. Desafortunadamente, la mayoría de las preguntas son muy específicas para casos de uso individuales y no presentan una guía general a seguir. Tampoco pude encontrar ninguna respuesta directa en los documentos.
El asunto:
Simplemente estaba tratando de hacer esto:
// helper.ts import fs from 'fs'; import util from 'util' const accessPromisfied = util.promisfy(fs.access); async function access(path:string){ try{ await accessPromisfied(path); return true; } catch { return false; } } async function someFunction(){ try{ let result = await access() if(result){ //some more logic here . . return true; } }catch{ return false; } } export default {access, someFunction} // helper.spec.ts import * as helper from './helper.ts'; describe("The test", () => { afterEach(() => { sinon.restore(); }) it("Should JUST work like we all wish", async () => { // stub acccess to resolve false const stubAccess = sinon.stub(helper, 'access').resolve(false); // rest of test code }) })Las preguntas
Finalmente, ¡tenga en cuenta que estoy usando nextjs, ESM en mi proyecto!