// jestSetup.ts // include this line for mocking react-native-gesture-handler import 'react-native-gesture-handler/jestSetup'; jest.mock("expo-sqlite", () => { const { DatabaseSync } = require("node:sqlite"); const db = new DatabaseSync(":memory:"); const { MIGRATE_UP } = jest.requireActual("./app/lib/migrations"); const openDatabaseAsync = async (name: string) => { return { closeAsync: jest.fn(() => db.close()), executeSql: jest.fn((sql: string) => db.exec(sql)), runAsync: jest.fn(async (sql: string, params = []) => { for (let m of Object.values(MIGRATE_UP)) { for (let stmt of m) { const s = db.prepare(stmt); s.run(); } } const stmt = db.prepare(sql); // console.log("Running %s with %s", sql, params); try { stmt.run(params); } catch (e) { throw new Error( `running ${sql} with params ${JSON.stringify(params)}: ${e}` ); } }), getFirstAsync: jest.fn(async (sql: string, params = []) => { for (let m of Object.values(MIGRATE_UP)) { for (let stmt of m) { const s = db.prepare(stmt); s.run(); } } const stmt = db.prepare(sql); // const result = stmt.run(...params); return stmt.get(params); }), }; }; return { migrateDb: async (direction: "up" | "down" = "up") => { const db = await openDatabaseAsync("translation_terrace"); for (let m of Object.values(MIGRATE_UP)) { for (let stmt of m) { await db.executeSql(stmt); } } }, openDatabaseAsync, }; }); // include this section and the NativeAnimatedHelper section for mocking react-native-reanimated jest.mock('react-native-reanimated', () => { const Reanimated = require('react-native-reanimated/mock'); // The mock for `call` immediately calls the callback which is incorrect // So we override it with a no-op Reanimated.default.call = () => {}; return Reanimated; }); // Silence the warning: Animated: `useNativeDriver` is not supported because the native animated module is missing // jest.mock('react-native/Libraries/Animated/NativeAnimatedHelper');