doc is an instance of pdfkit document...
import PDFDocument from 'pdfkit'
const doc = new PDFDocument()
...which gets passed to my function:
export const outputTitle = (doc, title) => {
if (!title) return null
doc
.fontSize(15)
.font('Helvetica-Bold')
.text(title, 380, 160)
}
Now I need to write unit tests for this functions using jest.
describe('outputTitle()', () => {
const doc = jest.fn()
test('should return null if parameter title is missing', () => {
// SETUP
const title = undefined
// EXECUTE
const result = outputTitle(doc, title)
// VERIFY
expect(result).toBeNull()
})
test('should call doc()', () => {
// ???
})
})
But how do I test the second part, which is the case of passing a title value? I think my mock of doc
is wrong.
Aucun commentaire:
Enregistrer un commentaire