Home Blog Talks

Test expo-sqlite in Jest: expo-sqlite-mock

2024-08-09

Background

Expo is the officially recommended framework for React Native, which can significantly enhance the development efficiency of apps.

expo-sqlite is the official plugin of Expo, supporting the use of Sqlite in the app.

By using expo-sqlite, it is easy to overcome the limitations of built-in storage space on various platforms, allowing for the persistent storage of more data on mobile devices.

However, expo-sqlite cannot run in the testing environment and can only run in end-to-end tests.

So I created expo-sqlite-mock to facilitate unit testing based on Jest.

How to Use

  1. Install dependencies: npm install -D expo-sqlite-mock or bun add -D expo-sqlite-mock.
  2. Add jest configuration (usually in package.json) "setupFilesAfterEnv": ["expo-sqlite-mock/src/setup.ts"] and "testTimeout": 10000.

References

Back to all posts