9

I have a component I'm mounting with Enzyme. There is an object that is defined inside the constructor of the component. I need to read values inside that object. How do I do this? If I was using the browser, I would use console.log(this.object.property) in the constructor or other function. In Jest, this doesn't seem to work. I tried running console.log in my test() function by:

console.log(wrapper.instance().object)

but it only showed me the default props from the object.
My prefered way would be to see console.log anywhere in the component. Is there a way to enable that? Otherwise, what is the best way to get access to properties of rendered components in Enzyme so I can do a console.log in one of my test() functions?

  • Try adding `--verbose false`? Take a look at https://stackoverflow.com/questions/48695717/console-log-statements-output-nothing-at-all-in-jest – Subhendu Kundu Feb 08 '19 at 16:11
  • That worked, I just couldn't figure out the syntax. in package.json I updated the line for the test script to be "test": "react-scripts test --env=jsdom --verbose=false" – Brandon Keith Biggs Feb 08 '19 at 19:46

2 Answers2

20

You can use console.log(wrapper.debug());

Mwibutsa Floribert
  • 1,824
  • 14
  • 21
7

Adding --verbose false will fix the issue.
The test line in package.json should look something like:
"test": "react-scripts test --env=jsdom --verbose=false",

Just like Console.log statements output nothing at all in Jest suggested.

Subhendu Kundu
  • 3,618
  • 6
  • 26
  • 57