Does Jest swallow console.log
output?
// __tests__/log.test.js
it(\'logs\', () => {
console.log(\'hey\') // expect to see \"hey\" printed in t
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.
I found a work around, despite the fact that sadly neither TERM=dumb
, nor verbose: false
nor upgrading to version 24 worked (I'm on 24.9). Just spy on the console, and you can see the results. Set it up with this:
const consoleSpy = jest.spyOn(console, 'log')
And then view the calls after running your tests using:
consoleSpy.mock.calls[0][0]
Try adding --verbose
to the Jest arguments.
This worked for me.
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.
Update: this issue should be fixed as of Jest 24.
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.