Use logging

  • To run tests with some extra debugging info, you can pass a --log-level:

yarn test:unit --log-level debug 
  • You can put a console.log() in your test code. When you run the test, the output will be in the command line.

Use Chrome devtools to debug unit tests

  1. Go to chrome://inspect/.

  2. Add a debugger statement in your test code and if you want to run only your test add the .only on your test like so. Make sure to remove the .only once you are done.

      it.only('testing something', () => {
  3. run in the terminal

      $ BABEL_ENV=test node_modules/.bin/mocha --inspect-brk --opts src/platform/testing/unit/mocha.opts --recursive '{test,src}/**/*.unit.spec.js?(x)' src/platform/testing/unit/helper.js
  4. Go to your Node Chrome Developer Tools. Under Remote Target you should see your test running. Click on the link where your test is running to open the debugger tool.

  5. You will want to press the debugger play button to start the program. It will initially pause on the first line of code.

  6. It might take awhile for the tests to setup, just be patient and eventually it will run.

  7. Once the test runs, your code should break at your debugger statement.

Use VSCode's debugging tool for unit tests

  1. Add this Mocha Tests configuration to your .vscode/launch.json file

        "version": "0.2.0",
        "configurations": [
                "type": "node",
                "request": "launch",
                "name": "Mocha Tests",
                "env": {"BABEL_ENV": "test"},
                "runtimeExecutable": "${workspaceFolder}/node_modules/.bin/mocha",
                "runtimeArgs": [
                "port": 9229
  2. Now you can add breakpoints or debugger statements to debug your code through the VSCode debugger tools.