Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Console.log statements output nothing at all in Jest

People also ask

How do I get rid of console error in Jest?

To disable console inside unit tests with Jest, we can use the --silent option or set the console methods to mocked functions. to run jest with the --silient to disable console output when running tests.

What does console log () do?

The console. log() is a function in JavaScript which is used to print any kind of variables defined before in it or to just print any message that needs to be displayed to the user.


You can run both options together like this --watch --verbose false if you want to also be watching the files and see the output.

for one time runs just do --verbose false


As per comment on https://github.com/facebook/jest/issues/2441,

Try setting verbose: false (or removing it) in the jest options in package.json.


Jest suppresses the console log message by default. In order to show the console log message, set silent option to false at the command line

set --silent=false in the command line:

npm run test -- --silent=false


Check for your command line flags in package.json to see that you don't have --silent in there.


in addition to --verbose option which can cause this as mentioned, be aware that the --watch may also cause this bug.


Also be sure that your jest config does not have silent: true. In my case, I didn't realize that someone else had added that to our config.

I don't see it in the list of config options, but the command line flag is documented here.