Chutzpah coverage result smaller than 100% (due to private methods?)

时光怂恿深爱的人放手 提交于 2020-01-14 02:08:08

问题


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% ?


回答1:


I can answer Question A: You can use the chutzpah.json file to specify exclusions: "CodeCoverageExcludes": ["path1","path2","path3","etc"] As far as I know, you can only exclude files, though, not specific lines.

Update: yeah, blanket.js is the default code coverage tool, and it only excludes at the file level.

Question B I'm also trying to figure out.



来源:https://stackoverflow.com/questions/37298684/chutzpah-coverage-result-smaller-than-100-due-to-private-methods

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!