I am using the html-pdf package in my nodejs code (not in Typescript). Now, this package has a create()
function which is chained with the toBuffer()
function. I am unit testing my code using Jest and want to mock this call pdf.create(html).toBuffer()
.
var pdf = require('html-pdf');
pdf.create(html).toBuffer(function(htmlToPdfError, buffer){
if (htmlToPdfError) {
reject(htmlToPdfError);
}
resolve(buffer.toString('base64'));
});
EDIT: I am trying to use the following code in my spec file to make the module:
jest.mock('html-pdf', () => ({
create: jest.fn(() => {
return Promise.resolve();
})
}));
This is helping me mock the create()
function but I do not know how to return a object in Promise.resolve which would have a toBuffer
function