koel/resources/assets/js/__tests__/services/ls.spec.ts

27 lines
719 B
TypeScript
Raw Normal View History

2022-04-15 14:24:30 +00:00
import { get, set, remove } from 'local-storage'
2022-04-24 08:50:45 +00:00
import { localStorageService } from '@/services'
2022-04-15 14:24:30 +00:00
describe('services/ls', () => {
it('gets an existing item from local storage', () => {
set('foo', 'bar')
2022-04-24 08:50:45 +00:00
expect(localStorageService.get('foo')).toBe('bar')
2022-04-15 14:24:30 +00:00
})
it('returns the default value for a non exising item', () => {
remove('foo')
2022-04-24 08:50:45 +00:00
expect(localStorageService.get('foo', 42)).toBe(42)
2022-04-15 14:24:30 +00:00
})
it('sets an item into local storage', () => {
remove('foo')
2022-04-24 08:50:45 +00:00
localStorageService.set('foo', 42)
2022-04-15 14:24:30 +00:00
expect(get('foo')).toBe(42)
})
it('correctly removes an item from local storage', () => {
set('foo', 42)
2022-04-24 08:50:45 +00:00
localStorageService.remove('foo')
2022-04-15 14:24:30 +00:00
expect(get('foo')).toBeNull()
})
})