Does Jest swallow console.log
output?
// __tests__/log.test.js
it('logs', () => {
console.log('hey') // expect to see "hey" printed in terminal
})
// terminal output
$ jest --forceExit
PASS __tests__/log.test.js
✓ logs (1ms) # where's "hey"?
The main reason I care is that I'm writing some async beforeAll
and afterAll
stuff, and I want to use console.log statements to debug the order of events.
The problem is that I was using jest --forceExit
. Jest's logging model saves all the logs and spits them out later. --forceExit
causes the process to bail before it reaches the spit-out-logs point.
This seems to be an ongoing issue.
With Node 10.7.0 and Jest 23.4.1, adding verbose: false
to the jest config (per this suggestion) worked for me.
Edit
Now that I've gone to Jest 23.6 I also need to pass TERM=dumb
as an environment variable, per Tamlyn's answer.
Another partial solution to the current bug affecting tests in --watch
mode is to pass TERM=dumb
as an environment variable.
TERM=dumb jest --watch
This has a small price in that it no longer clears the console before each test run so you have to scroll to see the results.