Reputation: 539
I am trying to reach more code coverage. I have an "informational" method that just triggers notification, and response is not required. How do I unit test it?
public error(message?: any, ...optionalParams: any[]) {
if (this.isErrorEnabled()) {
console.error(`${this.name}: ${message}`, ...optionalParams);
}
}
Upvotes: 12
Views: 12272
Reputation: 122157
You can test its side effects using spies, for example:
describe('error method', => {
it('should log an error on the console', () => {
spyOn(console, 'error');
error(...);
expect(console.error).toHaveBeenCalledWith(...);
});
...
});
Upvotes: 14