Merge pull request #547 from CartoDB/mockdate
Properly mock Date.now() for tests
This commit is contained in:
commit
2773c6d23e
6
package-lock.json
generated
6
package-lock.json
generated
@ -1649,6 +1649,12 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"mockdate": {
|
||||
"version": "2.0.2",
|
||||
"resolved": "https://registry.npmjs.org/mockdate/-/mockdate-2.0.2.tgz",
|
||||
"integrity": "sha1-WuDA6vj+I+AJzQH5iJtCxPY0rxI=",
|
||||
"dev": true
|
||||
},
|
||||
"moment": {
|
||||
"version": "2.22.2",
|
||||
"resolved": "https://registry.npmjs.org/moment/-/moment-2.22.2.tgz",
|
||||
|
@ -50,6 +50,7 @@
|
||||
"jshint": "~2.6.0",
|
||||
"libxmljs": "0.19.5",
|
||||
"mocha": "3.2.0",
|
||||
"mockdate": "^2.0.2",
|
||||
"shapefile": "0.3.0",
|
||||
"sqlite3": "4.0.0",
|
||||
"zipfile": "0.5.11"
|
||||
|
@ -5,6 +5,7 @@ require('../helper');
|
||||
var server = require('../../app/server')();
|
||||
var assert = require('../support/assert');
|
||||
var qs = require('querystring');
|
||||
var MockDate = require('mockdate');
|
||||
|
||||
describe('last modified header', function() {
|
||||
|
||||
@ -64,10 +65,7 @@ describe('last modified header', function() {
|
||||
api_key: 1234
|
||||
});
|
||||
var fixedDateNow = Date.now();
|
||||
var dateNowFn = Date.now;
|
||||
Date.now = function() {
|
||||
return fixedDateNow;
|
||||
};
|
||||
MockDate.set(fixedDateNow);
|
||||
assert.response(server,
|
||||
{
|
||||
url: '/api/v1/sql?' + query,
|
||||
@ -80,7 +78,7 @@ describe('last modified header', function() {
|
||||
statusCode: 200
|
||||
},
|
||||
function(err, res) {
|
||||
Date.now = dateNowFn;
|
||||
MockDate.reset();
|
||||
assert.equal(res.headers['last-modified'], new Date(fixedDateNow).toUTCString());
|
||||
done();
|
||||
}
|
||||
@ -93,10 +91,7 @@ describe('last modified header', function() {
|
||||
api_key: 1234
|
||||
});
|
||||
var fixedDateNow = Date.now();
|
||||
var dateNowFn = Date.now;
|
||||
Date.now = function() {
|
||||
return fixedDateNow;
|
||||
};
|
||||
MockDate.set(fixedDateNow);
|
||||
assert.response(server,
|
||||
{
|
||||
url: '/api/v1/sql?' + query,
|
||||
@ -109,7 +104,7 @@ describe('last modified header', function() {
|
||||
statusCode: 200
|
||||
},
|
||||
function(err, res) {
|
||||
Date.now = dateNowFn;
|
||||
MockDate.reset();
|
||||
assert.equal(res.headers['last-modified'], new Date(fixedDateNow).toUTCString());
|
||||
done();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user