【发布时间】:2020-11-17 00:35:33
【问题描述】:
我想测试一个 Typescript 项目的警告过程。我正在尝试测试的代码如下:
process.on('warning', (warning) => {
LoggingService.info('Warning, Message: ' + warning.message + ' Stack: ' + warning.stack, 'warning');
});
我使用sinnon.spy进行如下测试:
it('Check warning process', (done) => {
const spy = sinon.spy(LoggingService, 'info');
process.on('uncaughtException', () => {
sinon.assert.calledWith(spy, "warning")
done()
})
process.emit('warning')
})
上面的测试用例出现以下错误:
Argument of type '"warning"' is not assignable to parameter of type '"disconnect"'.
由于警告过程是在我尝试测试的代码中定义的,我该如何解决此错误? 非常感谢,任何建议将不胜感激!
【问题讨论】:
标签: typescript unit-testing mocha.js sinon spy