I use Chutzpah to test my JavaScript test coverage. Here is an example for the coverage result when I run a single test file referenceFigureEdit.spec.js:
I would expect the coverage to be 100% but it is only 91.07%.
Clicking on the first line I can inspect my tested code in detail. Lines that are "not covered by the test" are highlighted:
Question A:
How can I
- tell Chutzpah that those methods have actually been executed or
- tell Chutzpah to not include those lines in the coverage result?
Are there some restrictions on where/when code has to be executed to be part of the successful coverage? I call the delegates inside my it-methods. Do they already need to be called during the construction of the module under test?
My tested code defines some delegate methods (e.g. "showErrors") that are passed to constructors (e.g. new saveCommand(..., showErrors)). The method declarations of that delegates are highlighted and not included in the coverage. However, those delegates are actually executed during the test and I would expect the coverage to be 100 %.
Even if the code in the showErrors delegate is private I would like to test it (whether private methods should be tested is not my question here). In order to execute the delegates in my tests, I mock the saveCommand. The mocked saveCommand publishes the passed delegate and in the test I explicitly call it:
sut.saveCommand.__showErrors();
expect(showAllMessagesSpy).toHaveBeenCalled();
The test executes successfully and is fine for me. However, the coverage result is not as expected.
Question B:
The main coverage results for the referenced file errorhandler.js shows a coverage of 27.59 %. I do not yet have a test for errorhandler.js. Does that number mean that 8 of the existing 29 statements of the errorhandler.js are executed while executing my main file referenceFigureEdit.js? My main file directly references errorhandler.js but does not directly reference utils.js. Where can I find some documentation on how to interpret those "sub-numbers" correctly and what is the purpose of the Total of 47.66% ?