Skip to content

validateDOMNesting(...): <tr> cannot appear as a child of <div> #71

@salomvary

Description

@salomvary

This test

test('renders row', () => {
    const Row = () => (
      <tr>
        <td>Hello</td>
      </tr>
    );

    expect(
      <Row />,
      'to deeply render as',
      <tr>
        <td>Hello</td>
      </tr>
    );
  });

Prints this warning:

    console.error
      Warning: validateDOMNesting(...): <tr> cannot appear as a child of <div>.
          in tr (created by Row)
          in Row
          in StatelessWrapper

Workaround:

test('renders row', () => {
    const Row = () => (
      <tr>
        <td>Hello</td>
      </tr>
    );

    expect(
      <table>
        <tbody>
          <Row />
        </tbody>
      </table>,
      'to deeply render as',
      <table>
        <tbody>
          <tr>
            <td>Hello</td>
          </tr>
        </tbody>
      </table>
    );
  });

Could unexpected-react somehow improve the situation by

  1. supressing such warnings
  2. or allowing to control how the rendered nodes are wrapped?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions