Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

console.log(Wrapper.debug()) not showing the react component

I am using enzyme with jest and trying to print out wrapper.debug but I am not getting output as shown in jest docs. what is wrong here? my test file:

import React  from 'react';
import Enzyme, {shallow} from 'enzyme';
import EnzymeAdapter from 'enzyme-adapter-react-16';
import App  from './../../components/App/App';



Enzyme.configure({ adapter : new EnzymeAdapter() });

it('should render without crashing', () => {
  const wrapper = shallow(<App />)


 console.log(wrapper.debug());

});

my console output is this :

 PASS  src/test/integration/App.test.js
  ● Console

    console.log src/test/integration/App.test.js:14
      <ContextConsumer>
        [function bound renderWrappedComponent]
      </ContextConsumer>


Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        2.8s
Ran all test suites related to changed files.
like image 324
sriram hegde Avatar asked May 03 '26 10:05

sriram hegde


1 Answers

The shallow rendering is useful to test a component as a unit so it won't dive and look for your component within <ContextConsumer>.

Some options:

  • You could shallow directly the component within <ContextConsumer>.
  • You could change shallow with mount which render the full DOM rendering (probably not your intent here).
  • Use .dive() which shallow render the one non-DOM child of the current wrapper. Doc
like image 126
GibboK Avatar answered May 06 '26 06:05

GibboK



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!