React-native-testing-library: Unable to find node on an unmounted component.

Created on 19 Jun 2020  Â·  1Comment  Â·  Source: callstack/react-native-testing-library

I wrote this test and it worked perfectly

describe('test', () => {
    it( 'should render all text', () => {
       const {getByText, getByTestId, debug} = render(
          <View>
            <View><Text>test1</Text></View>
            <View><Text>test2</Text></View>
            <View><Text>test3</Text></View>
          </View>
      });
});

I wanted to test each text alone so I edited the code to be like this .. I expected to work but it gave me this error

describe('test', () => {
      const {getByText, debug} = render(
          <View>
            <View><Text>test1</Text></View>
            <View><Text>test2</Text></View>
            <View><Text>test3</Text></View>
          </View>
      });
   it('should render test1', () => {
       debug();
        expect(getByText('test1')).toBeTruthy();
    });

   it('should render test2', () => {
       debug(); // return null
        expect(getByText('test2')).toBeTruthy(); // fails
    });

   it('should render test13, () => {
       debug(); // return null
        expect(getByText('test3')).toBeTruthy(); // fails
    });
});

Versions

npmPackages:
react: 16.9.0 => 16.9.0
react-native: 0.61.5 => 0.61.5
react-native-testing-library: ^1.13.0 => 1.13.0
react-test-renderer: ^16.13.1 => 16.13.1

Most helpful comment

It sounds like you're using RNTL v2, which runs cleanup() after each test. You'll need to move your render call to the test functions, even if it means more code to run – it's for the safety of running your component tests in isolation.

>All comments

It sounds like you're using RNTL v2, which runs cleanup() after each test. You'll need to move your render call to the test functions, even if it means more code to run – it's for the safety of running your component tests in isolation.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

benmonro picture benmonro  Â·  6Comments

jonmchan picture jonmchan  Â·  11Comments

deepakaggarwal7 picture deepakaggarwal7  Â·  3Comments

entiendoNull picture entiendoNull  Â·  6Comments

acollazomayer picture acollazomayer  Â·  3Comments