- Create __mocks__/ with react-native, expo-router, expo-constants, expo-status-bar, react-native-mmkv, @testing-library/react-native - Update vitest.config.ts with resolve aliases for all native modules - Add AuthScreen smoke test (3 tests) - Add HomeScreen smoke test (2 tests) - Add @types/react-test-renderer dev dependency - Total: 32 passing tests (27 store + 5 component)
47 lines
1.0 KiB
TypeScript
47 lines
1.0 KiB
TypeScript
/**
|
|
* Mock for react-native-mmkv in Vitest.
|
|
* In-memory storage that mimics MMKV API.
|
|
*/
|
|
const store = new Map<string, string | number | boolean>();
|
|
|
|
export class MMKV {
|
|
private id: string;
|
|
|
|
constructor(config?: { id?: string }) {
|
|
this.id = config?.id ?? 'default';
|
|
}
|
|
|
|
getString(key: string): string | undefined {
|
|
const val = store.get(`${this.id}:${key}`);
|
|
return typeof val === 'string' ? val : undefined;
|
|
}
|
|
|
|
set(key: string, value: string | number | boolean): void {
|
|
store.set(`${this.id}:${key}`, value);
|
|
}
|
|
|
|
delete(key: string): void {
|
|
store.delete(`${this.id}:${key}`);
|
|
}
|
|
|
|
contains(key: string): boolean {
|
|
return store.has(`${this.id}:${key}`);
|
|
}
|
|
|
|
clearAll(): void {
|
|
const prefix = `${this.id}:`;
|
|
for (const key of store.keys()) {
|
|
if (key.startsWith(prefix)) {
|
|
store.delete(key);
|
|
}
|
|
}
|
|
}
|
|
|
|
getAllKeys(): string[] {
|
|
const prefix = `${this.id}:`;
|
|
return Array.from(store.keys())
|
|
.filter((k) => k.startsWith(prefix))
|
|
.map((k) => k.slice(prefix.length));
|
|
}
|
|
}
|