translation-terrace/jestSetup.ts
2025-02-13 07:48:32 -08:00

31 lines
1.1 KiB
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);
// 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 = []) => {
const stmt = db.prepare(sql)
// const result = stmt.run(...params);
return stmt.get(params)
})
};
},
};
});
*/