How do you debug Jest Tests?

后端 未结 5 1416
庸人自扰
庸人自扰 2020-12-09 17:57

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

How do you debug Jest Tests ?

5条回答
  •  遥遥无期
    2020-12-09 18:33

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

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

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

    1. Open JavaScript Debug Terminal:

    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.

    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]

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

提交回复
热议问题