我一直在测试我的 Azure Functions,但无法模拟上下文日志函数。
例如,我有以下 Azure 函数:
module.exports = async function (context, req) {
if (req.query.isGood) {
context.log("Goooood!!!")
context.res = {
body: {
message: "This is good!"
}
};
} else {
context.log.error("Not gooood!!!")
context.res = {
status: 404,
body: {
message: "This is not good!"
}
};
}
}
Run Code Online (Sandbox Code Playgroud)
所以我想检查某个日志发生的次数,例如“log.error”发生一次,“log”发生两次,但我无法模拟这一点。
我尝试了几种组合,例如:
log: {
"": jest.fn(),
"error": jest.fn()
}
Run Code Online (Sandbox Code Playgroud)
此时我对如何模拟这些函数一无所知,并且想知道这是否可能?以及如何创建这些类型的函数?