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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With