debian-mirror-gitlab/spec/javascripts/lib/utils/cache_spec.js

66 lines
1.7 KiB
JavaScript
Raw Normal View History

2017-09-10 17:25:29 +05:30
import Cache from '~/lib/utils/cache';
describe('Cache', () => {
const dummyKey = 'just some key';
const dummyValue = 'more than a value';
let cache;
beforeEach(() => {
cache = new Cache();
});
describe('get', () => {
it('return cached data', () => {
cache.internalStorage[dummyKey] = dummyValue;
expect(cache.get(dummyKey)).toBe(dummyValue);
});
it('returns undefined for missing data', () => {
expect(cache.internalStorage[dummyKey]).toBe(undefined);
expect(cache.get(dummyKey)).toBe(undefined);
});
});
describe('hasData', () => {
it('return true for cached data', () => {
cache.internalStorage[dummyKey] = dummyValue;
expect(cache.hasData(dummyKey)).toBe(true);
});
it('returns false for missing data', () => {
expect(cache.internalStorage[dummyKey]).toBe(undefined);
expect(cache.hasData(dummyKey)).toBe(false);
});
});
describe('remove', () => {
it('removes data from cache', () => {
cache.internalStorage[dummyKey] = dummyValue;
cache.remove(dummyKey);
expect(cache.internalStorage[dummyKey]).toBe(undefined);
});
it('does nothing for missing data', () => {
expect(cache.internalStorage[dummyKey]).toBe(undefined);
cache.remove(dummyKey);
expect(cache.internalStorage[dummyKey]).toBe(undefined);
});
it('does not remove wrong data', () => {
cache.internalStorage[dummyKey] = dummyValue;
cache.internalStorage[dummyKey + dummyKey] = dummyValue + dummyValue;
cache.remove(dummyKey);
expect(cache.internalStorage[dummyKey]).toBe(undefined);
expect(cache.internalStorage[dummyKey + dummyKey]).toBe(dummyValue + dummyValue);
});
});
});