9 typescript karma-jasmine angular angular8
有没有办法将私有方法添加ng test --code-coverage
到 Angular 8 的代码覆盖率报告中?
我们的 Ng 测试代码覆盖率很低,因为它检查私有方法。
根据文章,私有方法不应该需要单元测试。只有调用私有方法的公共方法需要。
*阅读标签;如果任何方法以 为前缀public
,则应对其进行单元测试。团队也可以private
在方法之前开始放置。这种方法是否允许 ng test 找到需要测试的内容?
https://softwareengineering.stackexchange.com/questions/100959/how-do-you-unit-test-private-methods
https://anthonysciamanna.com/2016/02/14/should-private-methods-be-tested.html#:~:text=Unit%20Tests%20Should%20Only%20Test,are%20dependent%20on%20the%20object .
目前正在 Angular 8 中测试 Typescript。
代码覆盖率也会检查私有方法。
通常,调用私有方法有两种情况。
对于这种情况,您需要在测试中调用公共方法并直接覆盖底层私有方法并满足测试中的条件。
对于这种情况,您需要使用By.css捕获按钮并触发点击事件。
注意 :: 在引入 Angular ivy 之前,我们可以将按钮单击事件绑定到 TS 类中的私有方法,但从现在开始这是不可能的。它会给出编译错误。
Property 'onClickMethod' is private and only accessible within class 'AppComponent'
归档时间: |
|
查看次数: |
698 次 |
最近记录: |