translation-terrace/jestSetup.ts
2025-02-12 12:37:35 -08:00

24 lines
833 B
TypeScript

// jestSetup.ts
jest.mock('expo-sqlite', () => {
return {
openDatabaseAsync: async (name: string) => {
const {DatabaseSync} = require("node:sqlite")
const db = new DatabaseSync(':memory:');
return {
closeAsync: jest.fn(() => db.close()),
executeSql: jest.fn((sql: string) => db.exec(sql)),
runAsync: jest.fn(async (sql: string, params = []) => {
const stmt = db.prepare(sql);
stmt.run(params)
}),
getFirstAsync: jest.fn(async (sql : string, params = []) => {
const stmt = db.prepare(sql)
const result = stmt.run(params);
return stmt.all(params)[0]
})
};
},
};
});