add tests for custom date separator
This commit is contained in:
@@ -5,15 +5,15 @@ import indexTimestamp from '../../../lib/helpers/index_timestamp';
|
|||||||
|
|
||||||
const anchor = '2016-04-02T01:02:03.456'; // saturday
|
const anchor = '2016-04-02T01:02:03.456'; // saturday
|
||||||
|
|
||||||
describe('Index interval', function () {
|
describe('Index timestamp interval', function () {
|
||||||
describe('indexTimestamp construction', function () {
|
describe('construction', function () {
|
||||||
it('should throw given an invalid interval', function () {
|
it('should throw given an invalid interval', function () {
|
||||||
const init = () => indexTimestamp('bananas');
|
const init = () => indexTimestamp('bananas');
|
||||||
expect(init).to.throwException(/invalid.+interval/i);
|
expect(init).to.throwException(/invalid.+interval/i);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('indexTimestamp timestamps', function () {
|
describe('timestamps', function () {
|
||||||
let clock;
|
let clock;
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
@@ -24,6 +24,7 @@ describe('Index interval', function () {
|
|||||||
clock.restore();
|
clock.restore();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('formats', function () {
|
||||||
it('should return the year', function () {
|
it('should return the year', function () {
|
||||||
const timestamp = indexTimestamp('year');
|
const timestamp = indexTimestamp('year');
|
||||||
expect(timestamp).to.equal('2016');
|
expect(timestamp).to.equal('2016');
|
||||||
@@ -54,4 +55,22 @@ describe('Index interval', function () {
|
|||||||
expect(timestamp).to.equal('2016-04-02-01-02');
|
expect(timestamp).to.equal('2016-04-02-01-02');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('date separator', function () {
|
||||||
|
it('should be customizable', function () {
|
||||||
|
const separators = ['-', '.', '_'];
|
||||||
|
separators.forEach(separator => {
|
||||||
|
const str = `2016${separator}04${separator}02${separator}01${separator}02`;
|
||||||
|
const timestamp = indexTimestamp('minute', separator);
|
||||||
|
expect(timestamp).to.equal(str);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should throw if a letter is used', function () {
|
||||||
|
const separator = 'a';
|
||||||
|
const fn = () => indexTimestamp('minute', separator);
|
||||||
|
expect(fn).to.throwException();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user