zfben/expo-sqlite-mock

Use expo-sqlite with jest.

★ 22Forks 2TypeScriptGitHub ↗Compare

README

expo-sqlite-mock

License: MIT NPM Version

Use expo-sqlite with jest.

Notice

  • ^4.0.0 is for expo-sqlite >=55.
  • ^3.0.0 is for expo-sqlite >=53.
  • ^2.0.0 is for expo-sqlite ~52.
  • ^1.0.0 is for expo-sqlite ~51.

Usage

  1. npm install -D expo-sqlite-mock or bun add -D expo-sqlite-mock
  2. Add "setupFilesAfterEnv": ["expo-sqlite-mock/src/setup.ts"] and "testTimeout": 10000 to your jest config (It's in package.json for default expo project).

Example:

{
  "jest": {
    "preset": "jest-expo",
    "setupFilesAfterEnv": ["expo-sqlite-mock/src/setup.ts"],
    "testTimeout": 10000
  }
}

Advanced

You can set the EXPO_SQLITE_MOCK environment variable to a custom SQLite database location.

Tips:

  1. Please use JEST_WORKER_ID to avoid concurrent test cases writing to the same file.
  2. Update your .gitignore to ignore the SQLite database file.

Example:

it("test", async () => {
  // or you can set it beforeAll or beforeEach
  process.env.EXPO_SQLITE_MOCK = `${__dirname}/test_${process.env.JEST_WORKER_ID}.db`;

  // your test code

  // clear the env var
  delete process.env.EXPO_SQLITE_MOCK;
});

Changelog

  • 4.0.0

    • Compatible with expo-sqlite ~55 and expo ~55.
  • 3.0.4

    • Fix appears to be backward compatible with Expo Go SDK 55. (Thanks @nderevj)
  • 3.0.2

    • Constraint error handling.
  • 3.0.0

    • Compatible with expo-sqlite ~15 and expo ~53.
  • 2.2.0

    • Compatible with drizzle
    • Clean up the code
  • 2.1.0

    • Support custom SQLite database location by setting the EXPO_SQLITE_MOCK environment variable.
    • Update peer dependencies.
  • 2.0.1

    • Fix setup.
  • 2.0.0

    • Update for expo-sqlite ~52.
  • 1.0.0

    • Initial version.

Contributors

zfbendependabot[bot]nderevj

Issues