Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

227
Views
¿Cómo puedo burlarme de un método que se llama después de eso en broma?

Tengo el siguiente código que descarga un pdf:

 import html2pdf from 'html2pdf.js' export const addFooter = (pdf) => { const totalPages = pdf.internal.getNumberOfPages() ... } export const downloadPDF = async (...) => { const pdfContent = document.getElementById("export") const opts = {...} await html2pdf().from(pdfContent).set(opts).toPdf().get('pdf').then(addFooter).save() }

Me gustaría poder simular el método de guardado usando broma.

Hasta ahora tengo:

 jest.mock('html2pdf.js', () => () => ({ from: () => ({ set: () => ({ toPdf: () => ({ get: () => Promise.resolve({ internal: { getNumberOfPages: () => {} } }) }) }) }) }))

Pero ejecutar las pruebas me da:

 TypeError: (0 , _html2pdf.default)(...).from(...).set(...).toPdf(...).get(...).then(...).save is not a function

¿Quizás alguien tenga una idea de cómo simular el método de guardado?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!