Skip to content

No elements rendered with testing-library/react when using Material Renderers #1795

@crgmz

Description

@crgmz

Describe the bug

I'm writing tests with Jest and testing-library/react and I noticed the <JsonForms/> component and its children are not rendered. Any assertions on those elements fail.

Vanilla renderers do not have this issue, the form is rendered correctly and assertions pass with no issues.

Issue can be reproduced with 2.5.2 and 3.0.0-alpha.1

Expected behavior

<JsonForms/> component should render the form and its children correctly when rendered with @testing-library/react, whether it's using vanilla renderers or material renderers.

Steps to reproduce the issue

  1. npx create-react-app jsonform-test
  2. cd jsonform-test
  3. npm install @jsonforms/core @jsonforms/react @jsonforms/material-renderers @jsonforms/vanilla-renderers @material-ui/core @material-ui/icons
  4. Copy the following code into App.test.js and run tests npm test
import { render, screen } from '@testing-library/react';
import { JsonForms } from '@jsonforms/react';
import { materialCells, materialRenderers } from '@jsonforms/material-renderers';
import { vanillaCells, vanillaRenderers } from '@jsonforms/vanilla-renderers';
import { Box, Typography } from '@material-ui/core';

const schema = {
  type: 'object',
  properties: {
    name: {
      type: 'string',
    },
  },
};

const uischemaVanilla = {
  type: 'HorizontalLayout',
  elements: [
    {
      type: 'Control',
      label: 'Vanilla',
      scope: '#/properties/name',
    },
  ],
};

const uischemamaterial = {
  type: 'HorizontalLayout',
  elements: [
    {
      type: 'Control',
      label: 'Material',
      scope: '#/properties/name',
    },
  ],
};

const data = {
  name: 'John Doe',
};

const Component = () => (
  <div className='App'>
    <Box>
      <Typography>Typography</Typography>
    </Box>
    <JsonForms
      schema={schema}
      uischema={uischemaVanilla}
      data={data}
      renderers={vanillaRenderers}
      cells={vanillaCells}
    />
    <JsonForms
      schema={schema}
      uischema={uischemamaterial}
      data={data}
      renderers={materialRenderers}
      cells={materialCells}
    />
  </div>
);

test('render jsonforms', () => {
  render(<Component />).debug();
  expect(screen.getByText(/vanilla/i)).toBeInTheDocument();
  expect(screen.getByText(/material/i)).toBeInTheDocument();
});
  1. Vanilla assertion will pass while material assertion fails.
  2. The rendered DOM contains material components and JsonForms with vanilla renderers, but JsonForms with material renderers is not rendered
<body>
      <div>
        <div
          class="App"
        >
          <div
            class="MuiBox-root MuiBox-root-1"
          >
            <p
              class="MuiTypography-root MuiTypography-body1"
            >
              Typography
            </p>
          </div>
          <div
            class="horizontal-layout"
          >
            <div
              class="horizontal-layout-item horizontal-layout-1"
            >
              <div
                class="control root_properties_name"
                id="#/properties/name"
              >
                <label
                  class=""
                  for="#/properties/name-input"
                >
                  Vanilla
                </label>
                <input
                  class="validate valid input"
                  id="#/properties/name-input"
                  type="text"
                  value="John Doe"
                />
                <div
                  class="validation input-description"
                />
              </div>
            </div>
          </div>
        </div>
      </div>
    </body>

Screenshots

No response

In which browser are you experiencing the issue?

@testing-library/react 11.1.0

Framework

React

RendererSet

Material

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions