1

I have a component with a lifecycle method added by the navigation library - React Native Navigation (https://wix.github.io/react-native-navigation/#/docs/Usage?id=screen-lifecycle).

I must call this lifecycle method (componentDidAppear) in tests so that my component render correctly.

I was able to call this method on the component instance when I used React Test Renderer. How do I call it with React Native Testing Library? How can I get test renderer instance in RN Testing-Library?

bentzy
  • 1,244
  • 2
  • 15
  • 31

1 Answers1

2

You can get to it via the getByType function:

const subject = render(<SomeComponent />);
subject.getByType(SomeComponent).instance.componentDidAppear()

Note how instance is a property on the interface, not a function (as is the case for some other libraries).

Jeroen Vannevel
  • 43,651
  • 22
  • 107
  • 170