9

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.
skyboyer
  • 22,209
  • 7
  • 57
  • 64
sriram hegde
  • 2,301
  • 5
  • 29
  • 43

1 Answers1

1

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
GibboK
  • 71,848
  • 143
  • 435
  • 658