I am writing test cases for winston custom format, but here the printf
from winston does the custom format. So how can I test the customFormat
, using jest.
Here the customFormat
which I am exporting is a variable, how can I test this one, in jest coverage report this line is not covered. So how can test this one
//winston.js
const customFormat = printf((log) => {
return `${log.level} -- ${log.label} -- ${log.message} `;
});
const logger = () => createLogger({
format: combine(
label({
label: "test label"
}),
format.timestamp(),
customFormat,
),
transports: [
new transports.File(options.file),
],
exitOnError: false, // do not exit on handled exceptions
});
module.exports = {
logger,
customFormat,
printf
};
// winston.test.js
describe('winton test cases', () => {
test("check custom format is returning", () => {
console.log(customFormt) // undeifned
expect(customFormat).toEqual("info -- winston.js -- dummy text")
})
})