title: How to see stacktrace / cause of an error in Jest?
body: <p>I'm trying to debug a nodeJS app.
  I have some code which causes an error, a variable is undefined.
  When I run the code normally, the error is very clear and easy to find:</p>
  <p>without jest:</p>
  <pre><code>➜  server git:(dc/build) ✗ node test/runner.js
  /Users/dc/dev/exiteer/xbot/server/src/mup/Story.js:24
      Logger.logObj('loaded story', {name: doc.name})
                                           ^
  
  ReferenceError: doc is not defined
      at Story.reload (/Users/dc/dev/exiteer/xbot/server/src/mup/Story.js:24:42)
      at Game.reload (/Users/dc/dev/exiteer/xbot/server/src/mup/Game.js:48:16)
      at Object.&lt;anonymous&gt; (/Users/dc/dev/exiteer/xbot/server/test/runner.js:4:10)
  </code></pre>
  <p>Sweet, I can fix it.</p>
  <p>Now, Jest has some nice tooling for writing tests so I thought I'd try that.</p>
  <p>But the errors are seemingly impossible to track down:</p>
  <pre><code>➜  server git:(dc/build) ✗ npm run jest
  
  &gt; cbg@0.1.0 jest /Users/dc/dev/exiteer/xbot/server
  &gt; jest
  
   PASS  src/index.test.js
  (node:23114) UnhandledPromiseRejectionWarning: ReferenceError: doc is not defined
  (Use `node --trace-warnings ...` to show where the warning was created)
  (node:23114) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
  (node:23114) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
   FAIL  src/mup/Actor.test.js
    ● Console
  
      console.log
        actors undefined
  
        at Object.&lt;anonymous&gt; (src/mup/Actor.test.js:9:13)
  
    ● Game.js › can load a story
  
      expect(received).toHaveLength(expected)
  
      Matcher error: received value must have a length property whose value must be a number
  
      Received has value: undefined
  
         8 | 
         9 |     console.log('actors', game.story.room.name.actors)
      &gt; 10 |     expect(game.story.room.actors).toHaveLength(1);
           |                                    ^
        11 |     const actor = game.story.room.actors[0]
        12 |     const reply = actor.sayTo('hi')
        13 |     expect(reply).toBe('hi back from Sid')
  
        at Object.&lt;anonymous&gt; (src/mup/Actor.test.js:10:36)
  </code></pre>
  <p>This tells me where my <strong>tests</strong> failed, but I'd prefer to know where the actual error is. Tests aren't the end goal here, a working app is.</p>
  <p>Googling around I found and tried this but it gives the same error message.</p>
  <p><code>node --trace-warnings node_modules/.bin/jest --no-cache</code></p>
  <pre><code>➜  server git:(dc/build) ✗ npm run test
  
  &gt; cbg@0.1.0 test /Users/dc/dev/exiteer/xbot/server
  &gt; node --trace-warnings node_modules/.bin/jest --no-cache
  
  (node:23263) UnhandledPromiseRejectionWarning: ReferenceError: doc is not defined
      at emitUnhandledRejectionWarning (internal/process/promises.js:151:15)
      at processPromiseRejections (internal/process/promises.js:211:11)
      at processTicksAndRejections (internal/process/task_queues.js:98:32)
  (node:23263) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
  </code></pre>
  <p>which gives a tiny bit more info but an</p>
  <pre><code>    at emitUnhandledRejectionWarning (internal/process/promises.js:151:15)
      at processPromiseRejections (internal/process/promises.js:211:11)
      at processTicksAndRejections (internal/process/task_queues.js:98:32)
  </code></pre>
  <p>This is not very helpful for debugging my code.</p>
  <p>Also Jest seems to swallow all <code>console.log</code> as if it's doing the best to make debugging as painful as possible. When your environment doesn't even log, its a real WTF moment.</p>