Skip to content

Commit

Permalink
Added test for ttl
Browse files Browse the repository at this point in the history
  • Loading branch information
Andreas Hultgren committed Sep 7, 2013
1 parent 5b6726a commit ced8e5d
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,3 +191,32 @@ describe('function with context', function () {
test1.should.have.property('original').and.be.a('function');
});
});

describe('a short ttl', function () {
var cache = new hamster.Hamster({
ttl: 10
}),
called = 0;

function fn (arg1, callback) {
called++;
callback(arg1 + 1);
}

var test = cache(fn);

it('clears the cache', function (next) {
test(1, function () {
called.should.equal(1);
});

test(1, function () {
called.should.equal(1);

setTimeout(test.bind(null, 1, function () {
called.should.equal(2);
next();
}), 20);
});
});
});

0 comments on commit ced8e5d

Please sign in to comment.