简体   繁体   English

如何在浏览器中调试Jest测试?

[英]How to debug Jest tests in the browser?

How do you guys proceed when having to debug Jest tests? 你们在调试Jest测试时如何进行? I remember back in the days, when I was using Mocha, I could use a headless browser to do CLI testing but there was also the possibility of loading the tests into a browser and use more powerful debugging capabilities like Chrome Dev Tools. 我记得当年使用Mocha时,我可以使用无头浏览器进行CLI测试,但是也有可能将测试加载到浏览器中,并使用更强大的调试功能(例如Chrome Dev Tools)。 For example, console.log with Jest just plainly sucks. 例如,带有Jest的console.log显然很烂。

I tried to use https://jestjs.io/docs/en/troubleshooting and use Node Debugger but its behavior is erratic (it doesn't always connect to the debugger or stops at the right place) and console.log is not output to the console. 我尝试使用https://jestjs.io/docs/zh-CN/troubleshooting并使用Node Debugger,但是它的行为是不稳定的(它并不总是连接到调试器或停在正确的位置)并且未输出console.log到控制台。

Is there a way I'm not aware of of having the same functionality in Jest? 有没有一种我不知道Jest具有相同功能的方法?

As an alternative, I am using Visual Studio Code. 作为替代,我正在使用Visual Studio Code。 Through a "launch.json" file I start jest, and this way you can debug directly in your IDE. 通过“ launch.json”文件,我开始开玩笑,这样您就可以直接在IDE中进行调试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM