diff --git a/package.json b/package.json index 081c4f1..9b7b74c 100644 --- a/package.json +++ b/package.json @@ -34,6 +34,7 @@ "coveralls": "^2.11.15", "date-fns": "^1.21.1", "nyc": "^10.0.0", + "timekeeper": "^1.0.0", "xo": "^0.17.1" } } diff --git a/test/expired.in.js b/test/expired.in.js index abe040a..49a6358 100644 --- a/test/expired.in.js +++ b/test/expired.in.js @@ -1,6 +1,21 @@ import test from 'ava'; +import tk from 'timekeeper'; import expired from '../'; test('expired.in is a function', t => { t.is(typeof expired.in, 'function'); }); + +test('expired.in returns positive ms for valid cache', t => { + const date = new Date().toUTCString(); + const maxAge = 300; + const headers = { + date: date, + age: 0, + 'cache-control': `public, max-age=${maxAge}` + }; + + tk.freeze(date); + t.is(expired.in(headers), maxAge * 1000); + tk.reset(); +});