react-native-testing-library icon indicating copy to clipboard operation
react-native-testing-library copied to clipboard

`rerender`/`update` is not working correctly when unmounting root component

Open mdjastrzebski opened this issue 3 years ago • 0 comments

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
``

mdjastrzebski avatar Jun 24 '22 08:06 mdjastrzebski