@@ -1,4 +1,5 @@
|
||||
const InMemoryCacheAdapter = require('../lib/Adapters/Cache/InMemoryCacheAdapter').default;
|
||||
const InMemoryCacheAdapter = require('../lib/Adapters/Cache/InMemoryCacheAdapter')
|
||||
.default;
|
||||
|
||||
describe('InMemoryCacheAdapter', function() {
|
||||
const KEY = 'hello';
|
||||
@@ -7,12 +8,12 @@ describe('InMemoryCacheAdapter', function() {
|
||||
function wait(sleep) {
|
||||
return new Promise(function(resolve) {
|
||||
setTimeout(resolve, sleep);
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
it('should expose promisifyed methods', (done) => {
|
||||
it('should expose promisifyed methods', done => {
|
||||
const cache = new InMemoryCacheAdapter({
|
||||
ttl: NaN
|
||||
ttl: NaN,
|
||||
});
|
||||
|
||||
// Verify all methods return promises.
|
||||
@@ -20,38 +21,39 @@ describe('InMemoryCacheAdapter', function() {
|
||||
cache.put(KEY, VALUE),
|
||||
cache.del(KEY),
|
||||
cache.get(KEY),
|
||||
cache.clear()
|
||||
cache.clear(),
|
||||
]).then(() => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should get/set/clear', (done) => {
|
||||
it('should get/set/clear', done => {
|
||||
const cache = new InMemoryCacheAdapter({
|
||||
ttl: NaN
|
||||
ttl: NaN,
|
||||
});
|
||||
|
||||
cache.put(KEY, VALUE)
|
||||
cache
|
||||
.put(KEY, VALUE)
|
||||
.then(() => cache.get(KEY))
|
||||
.then((value) => expect(value).toEqual(VALUE))
|
||||
.then(value => expect(value).toEqual(VALUE))
|
||||
.then(() => cache.clear())
|
||||
.then(() => cache.get(KEY))
|
||||
.then((value) => expect(value).toEqual(null))
|
||||
.then(value => expect(value).toEqual(null))
|
||||
.then(done);
|
||||
});
|
||||
|
||||
it('should expire after ttl', (done) => {
|
||||
it('should expire after ttl', done => {
|
||||
const cache = new InMemoryCacheAdapter({
|
||||
ttl: 10
|
||||
ttl: 10,
|
||||
});
|
||||
|
||||
cache.put(KEY, VALUE)
|
||||
cache
|
||||
.put(KEY, VALUE)
|
||||
.then(() => cache.get(KEY))
|
||||
.then((value) => expect(value).toEqual(VALUE))
|
||||
.then(value => expect(value).toEqual(VALUE))
|
||||
.then(wait.bind(null, 50))
|
||||
.then(() => cache.get(KEY))
|
||||
.then((value) => expect(value).toEqual(null))
|
||||
.then(value => expect(value).toEqual(null))
|
||||
.then(done);
|
||||
})
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user