|
| 1 | +import { createMMKV } from 'react-native-mmkv'; |
| 2 | +describe('Example test', () => { |
| 3 | + let storage: MMKV; |
| 4 | + |
| 5 | + beforeAll(() => { |
| 6 | + storage = createMMKV(); |
| 7 | + }); |
| 8 | + |
| 9 | + it('functions correctly', () => { |
| 10 | + storage.set('testString', 'value'); |
| 11 | + storage.set('testNumber', 99); |
| 12 | + storage.set('testBoolean', false); |
| 13 | + |
| 14 | + expect(storage.getString('testString')).toStrictEqual('value'); |
| 15 | + expect(storage.getNumber('testString')).toBeUndefined(); |
| 16 | + expect(storage.getBoolean('testString')).toBeUndefined(); |
| 17 | + expect(storage.getString('testNumber')).toBeUndefined(); |
| 18 | + expect(storage.getNumber('testNumber')).toStrictEqual(99); |
| 19 | + expect(storage.getBoolean('testNumber')).toBeUndefined(); |
| 20 | + expect(storage.getString('testBoolean')).toBeUndefined(); |
| 21 | + expect(storage.getNumber('testBoolean')).toBeUndefined(); |
| 22 | + expect(storage.getBoolean('testBoolean')).toStrictEqual(false); |
| 23 | + expect(storage.getAllKeys()).toEqual( |
| 24 | + expect.arrayContaining(['testString', 'testNumber', 'testBoolean']) |
| 25 | + ); |
| 26 | + |
| 27 | + storage.remove('testBoolean'); |
| 28 | + expect(storage.contains('testBoolean')).toBeFalsy(); |
| 29 | + expect(storage.getAllKeys()).toEqual( |
| 30 | + expect.arrayContaining(['testString', 'testNumber']) |
| 31 | + ); |
| 32 | + |
| 33 | + storage.clearAll(); |
| 34 | + expect(storage.toString()).toStrictEqual('MMKV (mmkv.default): []'); |
| 35 | + }); |
| 36 | +}); |
0 commit comments