在我的模块中编写 Node CLI 我有一个console.log
with chalk,例如:
console.log(
chalk.green(`${delta}:`),
chalk.white(`\nAPI: ${apiPath}`),
)
当我运行 Jest 代码覆盖率时--coverage
,我被提醒我没有测试,所以我写道:
test(`Test console log`, async () => {
await mod(params)
await expect(console.log).toBe(`${delta}:\nAPI: ${apiPath}`)
})
但我得到一个错误:
Expected: "string"
Received: [Function log]
我尝试的研究的第二次尝试:
test(`Test console log`, async () => {
await mod(params)
await expect(console.log).toHaveBeenCalledWith(`${delta}:\nAPI: ${apiPath}`)
})
但我得到一个错误:
Received has type: function
Received has value: [Function log]
研究:
使用 Jest 如何测试console.log
使用粉笔的?