Browse Source

Add tests for currentDate argument

pull/7/head
Luke Childs 8 years ago
parent
commit
0c8ee83783
  1. 12
      test/expired.in.js
  2. 13
      test/expired.js

12
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);
});

13
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)));
});

Loading…
Cancel
Save