diff --git a/test/expired.in.js b/test/expired.in.js index 52be2bd..f267d18 100644 --- a/test/expired.in.js +++ b/test/expired.in.js @@ -51,3 +51,15 @@ test('expired.in returns negative ms for stale cache', t => { t.is(expired.in(headers), expiredIn); tk.reset(); }); + +test('expired.in accepts currentDate argument', t => { + const date = new Date(new Date().toUTCString()); + const headers = { + date: date.toUTCString(), + age: 0, + 'cache-control': 'public, max-age=300' + }; + + t.is(expired.in(headers, date), 300000); + t.is(expired.in(headers, addSeconds(date, 500)), -200000); +}); diff --git a/test/expired.js b/test/expired.js index 8def6ec..ff4b9ad 100644 --- a/test/expired.js +++ b/test/expired.js @@ -1,5 +1,6 @@ import test from 'ava'; import subSeconds from 'date-fns/sub_seconds'; +import addSeconds from 'date-fns/add_seconds'; import expired from '../'; test('expired is a function', t => { @@ -25,3 +26,15 @@ test('expired returns true for stale cache', t => { t.true(expired(headers)); }); + +test('expired accepts currentDate argument', t => { + const date = new Date(); + const headers = { + date: date.toUTCString(), + age: 0, + 'cache-control': 'public, max-age=300' + }; + + t.false(expired(headers, date)); + t.true(expired(headers, addSeconds(date, 500))); +});