koa-lite/test/response/last-modified.js

37 lines
1 KiB
JavaScript
Raw Normal View History

'use strict';
const response = require('../helpers/context').response;
describe('res.lastModified', function(){
it('should set the header as a UTCString', function(){
const res = response();
const date = new Date();
res.lastModified = date;
res.header['last-modified'].should.equal(date.toUTCString());
2015-10-12 20:36:41 +00:00
});
it('should work with date strings', function(){
const res = response();
const date = new Date();
res.lastModified = date.toString();
res.header['last-modified'].should.equal(date.toUTCString());
2015-10-12 20:36:41 +00:00
});
it('should get the header as a Date', function(){
// Note: Date() removes milliseconds, but it's practically important.
const res = response();
const date = new Date();
res.lastModified = date;
(res.lastModified.getTime() / 1000)
.should.equal(Math.floor(date.getTime() / 1000));
2015-10-12 20:36:41 +00:00
});
2014-10-01 12:42:29 +00:00
2015-10-12 20:36:41 +00:00
describe('when lastModified not set', function(){
2014-10-01 12:42:29 +00:00
it('should get undefined', function(){
const res = response();
2014-10-01 12:42:29 +00:00
(res.lastModified === undefined).should.be.ok;
2015-10-12 20:36:41 +00:00
});
});
});