我如何模拟当时在开玩笑之后被调用的方法?
我有以下下载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()
}
我希望能够使用开玩笑模拟保存方法。
到目前为止,我有:
jest.mock('html2pdf.js', () => () => ({
from: () => ({
set: () => ({
toPdf: () => ({
get: () => Promise.resolve({
internal: {
getNumberOfPages: () => {}
}
})
})
})
})
}))
但是运行测试给我:
TypeError: (0 , _html2pdf.default)(...).from(...).set(...).toPdf(...).get(...).then(...).save is not a function
也许有人知道如何模拟保存方法?
I have the following code which downloads a 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()
}
I would like to be able to mock the save method using jest.
Up until now I have:
jest.mock('html2pdf.js', () => () => ({
from: () => ({
set: () => ({
toPdf: () => ({
get: () => Promise.resolve({
internal: {
getNumberOfPages: () => {}
}
})
})
})
})
}))
But running the tests give me:
TypeError: (0 , _html2pdf.default)(...).from(...).set(...).toPdf(...).get(...).then(...).save is not a function
Maybe someone have an idea how to mock the save method?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论