vendredi 13 mars 2020

Enzyme: Test children rendering failling with mount but passes with shallow

I'm using Enzyme + Jest to test some React components.

I have the following test:

describe('<Modal />', () => {
  let wrapper;

  it('should render children props', () => {
    wrapper = shallow(<Modal />);
    wrapper.setProps({
      children: <div className='should-render'>This should be rendered</div>
    });
    expect(wrapper.find('.should-render').length).toEqual(1);
  });
});

And it works just find. But, if I replace the shallow method from enzyme with mount the test fails (can't find a element with .should-render class).

Is this the expected behavior? I though that the difference between shallow and mount was the ability to access lifecycle methods but render worked the same.

Aucun commentaire:

Enregistrer un commentaire