-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMemoryCache.spec.ts
More file actions
50 lines (36 loc) · 1.4 KB
/
MemoryCache.spec.ts
File metadata and controls
50 lines (36 loc) · 1.4 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import "mocha";
import * as chai from "chai";
import { MemoryCache } from './MemoryCache';
const expect = chai.expect;
/* tslint:disable:only-arrow-functions */
describe('MemoryCache', function () {
it('should return previously set data', async function () {
const cache = new MemoryCache();
const testKey = 'key';
const testValue = 'value';
await cache.set(testKey, testValue);
const result = await cache.get(testKey);
expect(result).to.equal(testValue);
});
it('should not return expired data', async function () {
const cache = new MemoryCache({ maxAge: 5 });
const testKey = 'key';
const testValue = 'value';
await cache.set(testKey, testValue);
await new Promise((resolve) => setTimeout(resolve, 10));
const result = await cache.get(testKey);
expect(result).to.equal(undefined);
});
it('should not return expunged data', async function () {
const cache = new MemoryCache({ max: 1 });
const testKey1 = 'key1';
const testKey2 = 'key2';
const testValue = 'value';
await cache.set(testKey1, testValue);
await cache.set(testKey2, testValue);
const result1 = await cache.get(testKey1);
expect(result1).to.equal(undefined);
const result2 = await cache.get(testKey2);
expect(result2).to.equal(testValue);
})
});