-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathMemoryStorage.test.ts
29 lines (28 loc) · 1.04 KB
/
MemoryStorage.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
import {createMemoryStorage} from './createMemoryStorage'
describe('MemoryStorage', () => {
test('it behaves like localStorage', () => {
const storage = createMemoryStorage()
expect(storage.getItem('foo')).toBeNull()
expect(storage.getItem('bar')).toBeNull()
expect(storage.length).toBe(0)
storage.setItem('foo', 'lorem')
expect(storage.getItem('foo')).toBe('lorem')
expect(storage.getItem('bar')).toBeNull()
expect(storage.length).toBe(1)
expect(storage.key(0)).toBe('foo')
expect(storage.key(1)).toBeNull()
storage.setItem('bar', 'ipsum')
expect(storage.getItem('foo')).toBe('lorem')
expect(storage.getItem('bar')).toBe('ipsum')
expect(storage.length).toBe(2)
expect(storage.key(1)).toBe('bar')
storage.removeItem('foo')
expect(storage.getItem('foo')).toBeNull()
expect(storage.getItem('bar')).toBe('ipsum')
expect(storage.length).toBe(1)
expect(storage.key(0)).toBe('bar')
storage.clear()
expect(storage.getItem('bar')).toBeNull()
expect(storage.length).toBe(0)
})
})