how can i test the below snippet using jest. I am trying to test the winston custom format the printf
// sample.js
import {aa:{b}} = require("thirparty-package")
const a = () => {
return b((log) => {
return `log message will be ${log.message}`
})
}
module.exports = {
a
}
// sample.test.js
const customFunctions = require('./sample')
test('should check b function is called and returns a string', () => {
expect(customFunctions.a).toHaveBeenCalled() // throwing error
//jest.fn() value must be a mock function or spy.
})
If it's
b
that needs to be tested then it should be a spy, nota
.Third-party module should be mocked (a demo):