-
-
Notifications
You must be signed in to change notification settings - Fork 275
/
Copy pathcreateMMKV.mock.ts
30 lines (28 loc) · 979 Bytes
/
createMMKV.mock.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import type { NativeMMKV } from 'react-native-mmkv';
/* Mock MMKV instance for use in tests */
export const createMockMMKV = (): NativeMMKV => {
const storage = new Map<string, string | boolean | number>();
return {
clearAll: () => storage.clear(),
delete: (key) => storage.delete(key),
set: (key, value) => storage.set(key, value),
getString: (key) => {
const result = storage.get(key);
return typeof result === 'string' ? result : undefined;
},
getNumber: (key) => {
const result = storage.get(key);
return typeof result === 'number' ? result : undefined;
},
getBoolean: (key) => {
const result = storage.get(key);
return typeof result === 'boolean' ? result : undefined;
},
getAllKeys: () => Array.from(storage.keys()),
contains: (key) => storage.has(key),
trim: () => {},
recrypt: () => {
console.warn('Encryption is not supported in mocked MMKV instances!');
},
};
};