forked from mrousavy/react-native-mmkv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MMKV.test.ts
37 lines (31 loc) · 1.27 KB
/
MMKV.test.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
31
32
33
34
35
36
37
import { MMKV } from 'react-native-mmkv';
describe('Example test', () => {
let storage: MMKV;
beforeAll(() => {
storage = new MMKV();
});
it('functions correctly', () => {
storage.set('testString', 'value');
storage.set('testNumber', 99);
storage.set('testBoolean', false);
expect(storage.getString('testString')).toStrictEqual('value');
expect(storage.getNumber('testString')).toBeUndefined();
expect(storage.getBoolean('testString')).toBeUndefined();
expect(storage.getString('testNumber')).toBeUndefined();
expect(storage.getNumber('testNumber')).toStrictEqual(99);
expect(storage.getBoolean('testNumber')).toBeUndefined();
expect(storage.getString('testBoolean')).toBeUndefined();
expect(storage.getNumber('testBoolean')).toBeUndefined();
expect(storage.getBoolean('testBoolean')).toStrictEqual(false);
expect(storage.getAllKeys()).toEqual(
expect.arrayContaining(['testString', 'testNumber', 'testBoolean'])
);
storage.delete('testBoolean');
expect(storage.contains('testBoolean')).toBeFalsy();
expect(storage.getAllKeys()).toEqual(
expect.arrayContaining(['testString', 'testNumber'])
);
storage.clearAll();
expect(storage.toString()).toStrictEqual('MMKV (mmkv.default): []');
});
});