你如何调试 Jest 测试? [英] How do you debug Jest Tests?

查看:34
本文介绍了你如何调试 Jest 测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找不到关于调试我用 Jest 编写的单元测试的任何信息.

I can't find any information on debugging my unit tests written with Jest.

你如何调试 Jest 测试?

How do you debug Jest Tests ?

推荐答案

Jest 测试不需要 Chrome.这就是使用 Jest 而不是其他测试运行程序的全部意义所在.

You do not need Chrome for Jest tests. This is the whole point of using Jest instead of other test runners.

我发现的最简单的解决方案是使用 VS Code JavaScript 调试终端.

The simplest solution I found is to use VS Code JavaScript Debug Terminal.

它可以直接使用 Typescript 和 Nrvl.Nx 工作空间.

And it works with Typescript and Nrvl.Nx work-spaces out of the box.

  1. 打开命令面板并启动Debug: JavaScript Debug Terminal:

  1. 在该终端中以 Watch 模式运行测试 npm test --watch.
  2. 在文件中设置断点.
  3. 对要调试和保存的文件进行任何更改.
  4. watch 将对修改后的文件运行 Jest 测试.
  1. Run tests in that terminal in a Watch mode npm test --watch.
  2. Set a break-point in your file.
  3. Make any change in a file you want to debug and save.
  4. watch will run Jest tests against modified files.

当你想缩小--watch运行的文件数量时,在终端按p并输入一个模式,这只是你要测试的文件名的一部分然后按 [Enter]

When you want to narrow down the number of files run by the --watch, press p in the terminal and enter a pattern, which is just a part of the file name you want to test and hit [Enter]

要将其限制为文件中的单个测试 - 使用 f 聚焦它,因此将它(...)更改为适合(...)

To limit it to a single test in a file - focus it with f, so change it(...) to fit(...)

这篇关于你如何调试 Jest 测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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