koel/resources/assets/js/tests/services/lsTest.js

36 lines
911 B
JavaScript
Raw Normal View History

2016-11-26 03:25:35 +00:00
require('chai').should()
2015-12-13 04:42:28 +00:00
2016-11-26 03:25:35 +00:00
import localStorage from 'local-storage'
import { ls } from '../../services'
2015-12-13 04:42:28 +00:00
describe('services/ls', () => {
2016-11-26 03:25:35 +00:00
beforeEach(() => localStorage.remove('foo'))
2015-12-13 04:42:28 +00:00
2016-06-25 16:05:24 +00:00
describe('#get', () => {
it('correctly gets an existing item from local storage', () => {
2016-11-26 03:25:35 +00:00
localStorage('foo', 'bar')
ls.get('foo').should.equal('bar')
})
2015-12-13 04:42:28 +00:00
2016-06-25 16:05:24 +00:00
it('correctly returns the default value for a non exising item', () => {
2016-11-26 03:25:35 +00:00
ls.get('baz', 'qux').should.equal('qux')
})
})
2015-12-13 04:42:28 +00:00
2016-06-25 16:05:24 +00:00
describe('#set', () => {
it('correctly sets an item into local storage', () => {
2016-11-26 03:25:35 +00:00
ls.set('foo', 'bar')
localStorage('foo').should.equal('bar')
})
})
2015-12-13 04:42:28 +00:00
2016-06-25 16:05:24 +00:00
describe('#remove', () => {
it('correctly removes an item from local storage', () => {
2016-11-26 03:25:35 +00:00
localStorage('foo', 'bar')
ls.remove('foo')
var result = localStorage('foo') === null
result.should.be.true
})
})
})