use*_*588 10 jasmine karma-jasmine angular
我正在努力扩大代码范围.我有一个"信息"方法,只是触发通知,不需要响应.我该如何对它进行单元测试?
public error(message?: any, ...optionalParams: any[]) {
if (this.isErrorEnabled()) {
console.error(`${this.name}: ${message}`, ...optionalParams);
}
}
Run Code Online (Sandbox Code Playgroud)
jon*_*rpe 10
您可以使用间谍测试其副作用,例如:
describe('error method', => {
it('should log an error on the console', () => {
spyOn(console, 'error');
error(...);
expect(console.error).toHaveBeenCalledWith(...);
});
...
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5274 次 |
| 最近记录: |