基于Jasmine构建的Jest的代码覆盖率 [英] Code coverage for Jest built on top of Jasmine

查看:142
本文介绍了基于Jasmine构建的Jest的代码覆盖率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种方法可以在基于Jasmine的JavaScript Jest测试框架中进行代码覆盖?

Is there a way to have code coverage in the JavaScript Jest testing framework that is built on top of Jasmine?

内部框架没有打印出它得到的代码覆盖率.我还尝试使用伊斯坦布尔 JSCover ,但是他们都不起作用.

The internal framework does not print out the code coverage it gets. I've also tried using Istanbul, blanket, and JSCover, but none of them work.

推荐答案

使用 Jest 21.2.1 时,我可以在命令行上查看代码覆盖率,并通过传递--coverage来创建覆盖率目录到Jest脚本.下面是一些示例:

When using Jest 21.2.1, I can see code coverage at the command line and create a coverage directory by passing --coverage to the Jest script. Below are some examples:

我倾向于在本地安装Jest,在这种情况下,命令可能看起来像这样:

I tend to install Jest locally, in which case the command might look like this:

npx jest --coverage

我假设(尽管尚未确认),如果我在全球范围内安装Jest,这也将起作用:

I assume (though haven't confirmed), that this would also work if I installed Jest globally:

jest --coverage

非常稀疏的文档是此处

当我导航到 coverage/lcov-report 目录时,我发现了一个可以加载到浏览器中的 index.html 文件.它包括在命令行上打印的信息,以及其他信息和一些图形输出.

When I navigated into the coverage/lcov-report directory I found an index.html file that could be loaded into a browser. It included the information printed at the command line, plus additional information and some graphical output.

这篇关于基于Jasmine构建的Jest的代码覆盖率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆