'How to test deep links in react-navigation

I configured a deep link in react-navigation using the instructions on https://reactnavigation.org/docs/configuring-links#handling-nested-navigators. I have a few nested navigators so the linking config that I pass into the NavigationContainer is not trivial. So I'd like to write a test for it to prevent future bugs.

Any ideas on how I can write a test for it in Jest so that a given deep link goes to the screen that I wish?



Solution 1:[1]

You have a couple of options:

  • Mock Linking module and render your app, you should have correct pages rendered based on the returned link from getInitialURL
  • Import the getStateFromPath function and pass the path and a config and check the returned path

I know you asked for tests, but the linking config is type-checked if you specify a global RootParamList - which should already help with having correct nesting without the need for tests.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 satya164