javascript - 使用 jest 测试 winston 的格式
问题描述
我正在为 winston 自定义格式编写测试用例,但这里printf
来自 winston 的自定义格式。那么我该如何测试customFormat
, 使用 jest.
这里customFormat
我导出的是一个变量,我该如何测试这个,在开玩笑的覆盖率报告中,这条线没有被覆盖。那么如何测试这个
//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")
})
})
解决方案
推荐阅读
- java - 使用侦听器无构造函数初始化片段
- angular - 如何根据 ionic 4 中的日期推送日历上的数据计数
- node.js - MTLS - 为nodejs客户端生成证书
- flutter - Flutter WillPopScope 等待弹出窗口消失
- oracle11g - 有没有办法在 Oracle 中检索表标识符
- hive - 我正在尝试编写查询,但它不适用于滞后功能
- docker - apt-get install 在 Dockerfile 中找不到固定版本
- woocommerce - 在商店页面中显示最大可变价格 - Woocommerce
- html - 在 Rails 中按类别下拉搜索
- python - 如何将导入的模块封装成python中的多线程方法?