3 Steps to Writing Awesome React Native Tests

Whatever your approach to tests is - testing pyramid1 or testing trophy2 - you know that you need to write integration tests. In this post I’m going to show how to setup integration tests for React Native project.

Run tests for current file in VS Code

In my project we keep files and their tests next to each other.

src
├─ hashing.js
└─ hashing.spec.js

I wanted a quick way to run tests for currently open file regardless which one of the pair is opened. I accomplished this by adding tasks.json to my project.

Asserting on module imports with Jest

I work on React Native app and it’s important to do as little as possible at app start to reduce the time user has to wait before he can interact with the app. One of the things that helped to reduce wait time was switching from importing JavaScript modules at the top of the file to requiring modules in the functions that actully use them. But the challenge now is to prevent unwanted imports from appearing again.