0

I'm learning to write tests for my React Native apps. (Yes, finally!)

I have some questions about how to handle imports that in turn use NativeModules.

I understand that the test runner don't actually run the react native app on a device, and therefor cannot get the native module. So I need to mock these.

But what is the best way to do this? It seems like a huge and risky task to mock an entire API from native modules. And it feels difficult to figure out what parts actually is called under the hood for a simple test to run.

For instance, in my app I use Google Signin. The GoogleSignin dependency is imported in my App.tsx to run the configuration code as early as possible. This makes the simple default test to render the <App /> not possible because GoogleSignin import NativeModules and try to read a property off of that (which is undefined for the test runner).

How do people handle these scenarios? Feels like everyone using a library - and actually write tests for their own app - will run into the same problem.

Johan Nordberg
  • 3,621
  • 4
  • 33
  • 58

0 Answers0