Skip to content

bug: rerender/update is not working correctly when unmounting root component #996

@mdjastrzebski

Description

@mdjastrzebski

Describe the bug

The following test fails

test('rerender works when re-mounting root', () => {
  const result = render(<Text>Mt. Everest</Text>);
  result.rerender(
    <View>
      <Text>Śnieżka</Text>
    </View>
  );
  expect(result.getByText('Śnieżka')).toBeTruthy();
});

with following error:

image

while the following test works ok

test('rerender works when re-mounting nested component', () => {
  const result = render(
    <View>
      <Text>Mt. Everest</Text>
    </View>
  );
  screen.rerender(
    <View>
      <View>
        <Text>Śnieżka</Text>
      </View>
    </View>
  );
  expect(result.getByText('Śnieżka')).toBeTruthy();
});

Expected behavior

Both tests should work. Remounting root in rerender is not something you usually do, since you rather pass new props values. But that still could be used for some valid tests like for things like re-mounting (unmount + mount).

Steps to Reproduce

Write the first test, can be in RNTL repo.

Screenshots

None

Versions

  npmPackages:
    react: ^17.0.2 => 17.0.2 
    react-native: ^0.66.0 => 0.66.0 
    react-test-renderer: ^17.0.2 => 17.0.2
    @testing-library/react-native: 10.0.0 => 10.0.0
``

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