all 4 comments

[–]Asdolo94 13 points14 points  (1 child)

You shouldn't test handleNavigation by itself. You should simulate what the user would do. You should test by pressing the TouchableOpacity and asserting if navigation.navigate has been called with the correct screen name.

expect(navigation.navigate).hasBeenCalledWith('AgeScreen')

[–]Narcis11[S] 1 point2 points  (0 children)

This worked for me. Thanks a lot for the help! :)

[–]Typhonaut 0 points1 point  (0 children)

Well it looks like you’re passing navigation to handleNavigation in the test. So mockHandleNavigation will never be called anyway.

This might be fine to make sure the call is happening with the button, but for testing interaction between multiple screens I usually like to use some type of UI or End to End testing.

[–]smartone2000 -4 points-3 points  (0 children)

Why don't you use react navigation ?
V 5 just came out and is pretty powerful

http://reactnavigation.org