This repository has been archived by the owner on Jun 13, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
56 lines (47 loc) · 1.4 KB
/
test.js
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
51
52
53
54
55
56
var should = require('should');
var cache = require('./index');
describe('Test', function() {
beforeEach(function() {
cache.clear();
});
it('should set a key', function() {
cache.set('key', 'value');
cache.get('key').should.equal('value');
cache.exists('key').should.be.true;
cache.size().should.equal(1);
});
it('invalid key should return null', function() {
should(cache.get('invalid key')).be.null;
});
it('should set a key that expires', function(done) {
cache.set('timer', 'value', 100);
setTimeout(function() {
cache.get('timer').should.equal('value');
cache.exists('timer').should.be.true;
cache.size().should.equal(1);
}, 50);
setTimeout(function() {
cache.exists('timer').should.be.false;
cache.size().should.equal(0);
should(cache.get('timer')).be.null;
done();
}, 150);
});
it('should unset a key', function() {
cache.set('key', 'value');
cache.get('key').should.equal('value');
cache.exists('key').should.be.true;
cache.size().should.equal(1);
cache.unset('key');
cache.exists('key').should.be.false;
cache.size().should.equal(0);
should(cache.get('key')).be.null;
});
it('should clear', function() {
cache.set('key', 'value');
cache.set('anotherKey', 'anotherValue');
cache.size().should.equal(2);
cache.clear();
cache.size().should.equal(0);
});
});