2

It seems that some combination of --silent=false or maybe --verbose=false is needed to get console.log output from Jest. But none of these options seems to help (in Jest 29.3) when my test fails (i.e., throws an error):

test('console output', () => {
   console.log('this never prints')
   throw new Error('but why?!?') // or 'expect(true).toBe(false)'
})

Why, oh why, Jest, do you do this? A failing test is exactly when I need console (i.e. debugging) output the most.

How can I see console.log output regardless of whether something in the test throws an error?

Sasgorilla
  • 2,403
  • 2
  • 29
  • 56
  • Would running tests as just `node_modules\.bin\jest` work? This showed console.log output for me. Jest 29.3, Windows. package.json may have `--silent` flag, as mentioned in linked question, which prevents console output. – Renat Dec 01 '22 at 19:04
  • A fresh new environment of jest 29.3 works - [see it here](https://codesandbox.io/s/jest-test-forked-xqhqhv?file=/index.test.js). You should probably share your configs. – OfirD Dec 01 '22 at 19:28

1 Answers1

0
// Jest configuration file (jest.config.js)
module.exports = {
    errorOnDeprecated: true,
    verbose: true,
    forceExit: false,
};

The errorOnDeprecated option, when set to true, will cause Jest to throw an error whenever a deprecated feature is used. This will prevent Jest from suppressing the console output of the deprecated feature, and will allow you to see the full output of the test run.

ahuemmer
  • 1,653
  • 9
  • 22
  • 29