-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathStorage.test.tsx
68 lines (57 loc) · 2.12 KB
/
Storage.test.tsx
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import 'react-native';
import { beforeEach, describe, expect, it } from '@jest/globals';
import AsyncStorage from '@react-native-async-storage/async-storage';
import { Storage } from '../src/business/dao/Storage';
describe('Storage', () => {
let storage: Storage;
beforeEach(() => {
storage = new Storage();
AsyncStorage.clear();
});
it('stores and retrieves a value.', async () => {
await storage.setItem('key', 'value');
const retrievedValue = await storage.getItem('key');
expect(retrievedValue).toEqual('value');
});
it('removes a value.', async () => {
await storage.setItem('key', 'value');
await storage.removeItem('key');
const retrievedValue = await storage.getItem('key');
expect(retrievedValue).toBeNull();
});
it('clears the storage.', async () => {
await storage.setItem('key1', 'value1');
await storage.setItem('key2', 'value2');
await storage.clear();
const retrievedValue1 = await storage.getItem('key1');
const retrievedValue2 = await storage.getItem('key2');
expect(retrievedValue1).toBeNull();
expect(retrievedValue2).toBeNull();
});
});
describe('InMemoryStorage', () => {
let inMemoryStorage: Storage;
beforeEach(() => {
inMemoryStorage = Storage.newInMemoryInstance();
});
it('stores and retrieves a value.', async () => {
await inMemoryStorage.setItem('key', 'value');
const retrievedValue = await inMemoryStorage.getItem('key');
expect(retrievedValue).toEqual('value');
});
it('removes a value.', async () => {
await inMemoryStorage.setItem('key', 'value');
await inMemoryStorage.removeItem('key');
const retrievedValue = await inMemoryStorage.getItem('key');
expect(retrievedValue).toBeNull();
});
it('clears the storage.', async () => {
await inMemoryStorage.setItem('key1', 'value1');
await inMemoryStorage.setItem('key2', 'value2');
await inMemoryStorage.clear();
const retrievedValue1 = await inMemoryStorage.getItem('key1');
const retrievedValue2 = await inMemoryStorage.getItem('key2');
expect(retrievedValue1).toBeNull();
expect(retrievedValue2).toBeNull();
});
});