mardi 4 juin 2019

How to test component ShallowRenderer with context?

I have a shallow object like:

const wrapper= shallow(<Storage />,{context: {valley: valley}});

If I want to use ShallowRenderer rending this object and test it how to do? My shallowRender object is like:

import ShallowRenderer from 'react-test-renderer/shallow';

const renderer = new ShallowRenderer();
renderer.render(<Storage />,{context: {valley: valley}});
const result = renderer.getRenderOutput();

but the context doesn't inject into the Storage component yet.

If I want to use the fellow expect like:

expect(result.props.children).toEqual([
 <span className="heading">Title</span>,
 <Subcomponent foo="bar" />
 ]);

but My children are like:

  <Bootstrap(Row) className="pageTitleWrapper">
    <Col xs={0} sm={1} md={1} lg={1} as="div" />
    <Col xs={12} sm={10} md={10} lg={10} as="div">
      <h3>
        Murrumbidgee Valley
        : Average monthly storage
      </h3>
    </Col>
    <Col xs={0} sm={1} md={1} lg={1} as="div" />
  </Bootstrap(Row)>

which is { Row, Col } from 'react-bootstrap',(which is from other componenets) how should I compare the result?

Aucun commentaire:

Enregistrer un commentaire