File tree Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ smart people at [Hashrocket](http://hashrocket.com/).
1010For a steady stream of TILs from a variety of rocketeers, checkout
1111[ til.hashrocket.com] ( https://til.hashrocket.com/ ) .
1212
13- _ 655 TILs and counting..._
13+ _ 656 TILs and counting..._
1414
1515---
1616
@@ -450,6 +450,7 @@ _655 TILs and counting..._
450450- [ Alter The Display Name Of A Component] ( react/alter-the-display-name-of-a-component.md )
451451- [ Building A React App In The Browser] ( react/building-a-react-app-in-the-browser.md )
452452- [ create-react-app Comes With Lodash] ( react/create-react-app-comes-with-lodash.md )
453+ - [ Debug Jest Tests In create-react-app] ( react/debug-jest-tests-in-create-react-app.md )
453454- [ Defining State In A Simple Class Component] ( react/defining-state-in-a-simple-class-component.md )
454455- [ Destructure Variables As Props To A Component] ( react/destructure-variables-as-props-to-a-component.md )
455456- [ Dispatch Anywhere With Redux] ( react/dispatch-anywhere-with-redux.md )
Original file line number Diff line number Diff line change 1+ # Debug Jest Tests In create-react-app
2+
3+ When you put a ` debugger; ` statement in one of your Jest tests and
4+ run ` yarn test ` , the test runner will ignore the debug statement and run to
5+ completion. This is because Jest defaults to parallelizing tests which won't
6+ mix well with manual debugging intervention.
7+
8+ If we want to be able to run our Jest tests through a debugger. We will need
9+ two things. First, we need a debugging environment -- Chrome's devtools will
10+ work well for this. Second, we need our tests to run in band. The
11+ [ ` react-scripts `
12+ documentation] ( https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/template/README.md#debugging-tests )
13+ recommends adding a second, debug-specific test command to your
14+ ` package.json ` :
15+
16+ ``` javascript
17+ " scripts" : {
18+ " test:debug" : " react-scripts --inspect-brk test --runInBand --env=jsdom"
19+ }
20+ ```
21+
22+ You can now run ` yarn test:debug ` which will start a paused debug session.
23+ Open chrome at ` chrome://inspect ` to access and open the debugging session
24+ panel. Now, debug away.
You can’t perform that action at this time.
0 commit comments