Jest a minute… how to mock a class
Published in
3 min readJan 16, 2024
Let’s get right into it. Our example involves the npm package ‘pdfkit’. The way pdfkit is used in code looks something like this:
import pdfkit from 'pdfkit';
const doc = new pdfkit();
doc.text('This is page one of my pdf');
doc.addPage();
doc.text('This is page two of my pdf');
This is a very simple example which will create a pdf with two pages with some text on each page…