I'l*_*ack 6 javascript node.js jestjs
如何使用 Jest 进行测试return
例如使用 Lambda:
exports.handler = async (event, context, callback) => {
try {
const orders = await getOrders();
if (!orders) {
console.log("There is no Orders");
return; //<< How do test this?
}
// Something else
} catch (err) {
throw new;
}
};
Run Code Online (Sandbox Code Playgroud)
我能够测试控制台日志,但我也喜欢测试return预期
目前我在测试中使用这个:
it("should terminate if there is no order", async () => {
console.log = jest.fn();
let order = await func.handler();
expect(console.log.mock.calls[0][0]).toBe('There is no Orders');
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11762 次 |
| 最近记录: |