Skip to content

Commit

Permalink
unwrap Date objects
Browse files Browse the repository at this point in the history
  • Loading branch information
jamestalmage committed Jun 27, 2015
1 parent 525532e commit 413e784
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/expired.js
Expand Up @@ -145,6 +145,8 @@ function wrapExpiryFunction(fn) {
expiration = new Date(expiration).getTime();
} else if ('string' === typeof expiration) {
expiration = parseInt(expiration);
} else if (expiration instanceof Date) {
expiration = expiration.getTime();
}
return expiration;
}
Expand Down
15 changes: 15 additions & 0 deletions test/expired-test.js
Expand Up @@ -489,6 +489,21 @@ describe('expired', function(){
expect(fetch.callCount).to.equal(2);
});

it('expirations as Date objects', function() {
var resource = expired(fetch);
resource(cb1);
clock.tick();
cbs[0](null, {result:'a', expires:new Date(1000)});
clock.tick(999);
resource(cb2);
clock.tick();
expect(fetch.callCount).to.equal(1);
clock.tick(1);
resource(cb3);
clock.tick();
expect(fetch.callCount).to.equal(2);
});

it('error in copy function is passed to waiting callbacks', function() {
var error = new Error('myError');
var copy = sinon.stub();
Expand Down

0 comments on commit 413e784

Please sign in to comment.