I am trying to achieve more code coverage. I have an “informational” method that just triggers a notification and no response is required. How to do unit test?
public error(message?: any, ...optionalParams: any[]) { if (this.isErrorEnabled()) { console.error(`${this.name}: ${message}`, ...optionalParams); } }
You can check your 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(...); }); ... });
Source: https://habr.com/ru/post/1012341/More articles:How can I publish NUnit test results using Jenkins Pipeline? - nunitIonic: the camera asks for confirmation after each shot / takes several pictures - androidWhat is better between @HostListener and Renderer.listen? - angularDifference in calculating eigenvectors with Java and Python - javaforce the use of a specific constructor, used exclusively in specific code, nowhere else - c ++Why exec ("break") doesn't work inside a while loop - pythonReplace all occurrences of a string (in an array) with a single value - stringvoid javascript testing method - javascriptJava 8 Local Date in JavaScript Date - javaHow to automate the creation of a StructType for transferring RDD to a DataFrame - scalaAll Articles