Skip to content

Commit

Permalink
use sinon fakeTimer instead of setTimeout
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathias Schreck committed Feb 5, 2014
1 parent ac6f4c5 commit e91b5a6
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions test/shared/store/memory_store.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var MemoryStore = require('../../../shared/store/memory_store'),
sinon = require('sinon'),
should = require('chai').should();

describe('MemoryStore', function() {
Expand Down Expand Up @@ -31,17 +32,18 @@ describe('MemoryStore', function() {
should.not.exist(value);
});

it("should be able to expire a key", function(done) {
var value;
it("should be able to expire a key", function() {
var value,
fakeTimer = sinon.useFakeTimers();

store.set('will_expire', '1234', 0.01);
value = store.get('will_expire');
value.should.equal('1234');

setTimeout(function() {
value = store.get('will_expire');
should.not.exist(value);
done();
}, 11);
fakeTimer.tick(11);
value = store.get('will_expire');
should.not.exist(value);

fakeTimer.restore();
});
});

1 comment on commit e91b5a6

@spikebrehm
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, did not know about useFakeTimer

Please sign in to comment.