Create React App

Create React App

  • Getting started
  • Help
  • GitHub

›Testing

Welcome

  • About The Docs

Getting Started

  • Getting Started
  • Folder Structure
  • Available Scripts
  • Browsers & Features
  • Updating To New Releases

Development

  • Editor Setup
  • Developing Components In Isolation
  • Analyzing Bundle Size
  • HTTPS In Development

Styles and Assets

  • Adding Stylesheets
  • Adding CSS Modules
  • Adding Sass Stylesheets
  • Post-Processing CSS
  • Adding Images, Fonts, And Files
  • Using The public Folder
  • Code Splitting

Building your App

  • Installing A Dependency
  • Importing A Component
  • Using Global Variables
  • Adding Bootstrap
  • Adding Flow
  • Adding Relay
  • Adding A Router
  • Environment Variables
  • Making A Progressive Web App

Testing

  • Running Tests
  • Debugging Tests

Back-End Integration

  • Proxying In Development
  • Fetching Data
  • Integrating With An API
  • Title & Meta Tags

Deployment

  • Deployment

Advanced Usage

  • Can I Use Decorators?
  • Pre-Rendering Static HTML
  • Advanced Configuration
  • Alternatives To Ejecting

Support

  • Troubleshooting

Debugging Tests

There are various ways to setup a debugger for your Jest tests. We cover debugging in Chrome and Visual Studio Code.

Note: debugging tests requires Node 8 or higher.

Debugging Tests in Chrome

Add the following to the scripts section in your project's package.json

"scripts": {
    "test:debug": "react-scripts --inspect-brk test --runInBand"
  }

Place debugger; statements in any test and run:

$ npm run test:debug

This will start running your Jest tests, but pause before executing to allow a debugger to attach to the process.

Open the following in Chrome

about:inspect

After opening that link, the Chrome Developer Tools will be displayed. Select inspect on your process and a breakpoint will be set at the first line of the react script (this is done simply to give you time to open the developer tools and to prevent Jest from executing before you have time to do so). Click the button that looks like a "play" button in the upper right hand side of the screen to continue execution. When Jest executes the test that contains the debugger statement, execution will pause and you can examine the current scope and call stack.

Note: the --runInBand cli option makes sure Jest runs test in the same process rather than spawning processes for individual tests. Normally Jest parallelizes test runs across processes but it is hard to debug many processes at the same time.

Debugging Tests in Visual Studio Code

Debugging Jest tests is supported out of the box for Visual Studio Code.

Use the following launch.json configuration file:

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Debug CRA Tests",
      "type": "node",
      "request": "launch",
      "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/react-scripts",
      "args": [
        "test",
        "--runInBand",
        "--no-cache"
      ],
      "cwd": "${workspaceRoot}",
      "protocol": "inspector",
      "console": "integratedTerminal",
      "internalConsoleOptions": "neverOpen"
    }
  ]
}
← PreviousNext →
  • Debugging Tests in Chrome
  • Debugging Tests in Visual Studio Code
Create React App
Docs
Getting StartedDocumentation
Community
Stack OverflowSpectrumTwitter
More
GitHubStar
Facebook Open Source
Copyright © 2018 Facebook Inc.