@empathyco/x-storage-service
Version:
Storage service with TTL
34 lines • 1.29 kB
JavaScript
import { InMemoryStorageService } from '../in-memory-storage-service';
var storage;
var key = 'key';
var anotherKey = 'another-key';
var item = { a: 'item', b: true, c: 288 };
describe('testing InMemoryStorageService', function () {
beforeEach(function () {
storage = new InMemoryStorageService();
});
it('gets an item from storage', function () {
storage.setItem(key, item);
expect(storage.getItem(key)).toEqual(item);
});
it('removes an item from storage and returns it', function () {
storage.setItem(key, item);
expect(storage.removeItem(key)).toEqual(item);
});
it('clears all the items', function () {
storage.setItem(key, item);
storage.setItem(anotherKey, item);
expect(storage.clear()).toEqual(2);
expect(storage.getItem(key)).toBeNull();
expect(storage.getItem(anotherKey)).toBeNull();
});
it('does not allow you to save undefined values', function () {
storage.setItem(key, undefined);
expect(storage.getItem(key)).toBeNull();
});
it('allows you to save null values', function () {
storage.setItem(key, null);
expect(storage.getItem(key)).toBeNull();
});
});
//# sourceMappingURL=in-memory-storage-service.spec.js.map