【发布时间】:2020-11-13 16:28:27
【问题描述】:
抱歉,如果这是一个幼稚的问题。我对 Typescript 和 Mocha 测试比较陌生。我想测试以下进程以增加代码覆盖率:
process.on('unhandledRejection', (reason, p) => {
LoggingService.error(reason, 'unhandledRejection', 'Unhandled Rejection at:');
});
process.on('uncaughtException', (error) => {
LoggingService.error(error, 'unhandledRejection', 'Caught exception: ');
});
process.on('warning', (warning) => {
LoggingService.info('Warning, Message: ' + warning.message + ' Stack: ' + warning.stack, 'warning');
});
process.on('exit', (code) => {
LoggingService.error(null, 'NodeJs Exit', `Node.js process is about to exit with code: ${code}`);
});
如何在 mocha 中为进程编写测试?特别是,如果我想为unhandledRejection, uncaughtException, warning, exit 模拟process.on,我将如何做到这一点以及我会期待什么,因为这些进程没有return 语句?
提前致谢。
【问题讨论】:
标签: node.js typescript mocha.js