我试图达到更多的代码覆盖率。我有一个“信息”方法,该方法仅触发通知,不需要响应。如何进行单元测试?
public error(message?: any, ...optionalParams: any[]) {
if (this.isErrorEnabled()) {
console.error(`${this.name}: ${message}`, ...optionalParams);
}
}
您可以使用测试它的副作用间谍,例如:
describe('error method', => {
it('should log an error on the console', () => {
spyOn(console, 'error');
error(...);
expect(console.error).toHaveBeenCalledWith(...);
});
...
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句