mercredi 2 novembre 2016

Chai Testing type of component within another component

I am trying to test an HTML tag <tr></tr>. Here is my code:

const children = (<h1>Test</h1>);
    const renderComponent = () => shallow(
      <Table>
        <Tr>
          {children}
        </Tr>
      </Table>
    );


    describe("<Tr />", () => {
      it("should render a <Tr> tag ", () => {
        const renderedComponent = renderComponent();
        expect(renderedComponent.type()).toEqual("tr");
      });

      it("should have children", () => {
        const renderedComponent = renderComponent();
        expect(renderedComponent.contains(children)).toEqual(true);
      });
    });

So, previously I did not have the tags <Table></Table> but that gave me an undefined result. However, now it tests the first tag to equal which obviously is wrong.

Any clue how I can target the second component in renderComponent()???

Aucun commentaire:

Enregistrer un commentaire