I have been playing around with testing my Azure Functions, but I am unable to mock the context log function.
For example I have the following Azure Function:
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!"
}
};
}
}
So I want to check the amount of times a certain log occured, for example 'log.error' occured once and 'log' occured twice, but I am unable to mock this.
I tried a couple of combinations like:
log: {
"": jest.fn(),
"error": jest.fn()
}
At this point I'm clueless on how to mock these functions, and am wondering if it is even possible? And how do you create these kind of functions?