diff --git a/src/utils/index.js b/src/utils/index.js index a2367cb..fc4de8a 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -1,2 +1,3 @@ -export const isObject = o => o != null && typeof o === 'object'; +export const isDate = d => d instanceof Date; export const isEmpty = o => Object.keys(o).length === 0; +export const isObject = o => o != null && typeof o === 'object'; diff --git a/src/utils/index.spec.js b/src/utils/index.spec.js index bc0ae25..4bf65dc 100644 --- a/src/utils/index.spec.js +++ b/src/utils/index.spec.js @@ -1,10 +1,36 @@ import { expect } from 'chai'; import forEach from 'mocha-each'; -import { isEmpty, isObject } from './'; +import { isDate, isEmpty, isObject } from './'; describe('utils', () => { + describe('.isDate', () => { + forEach([ + [new Date()], + [new Date('2016')], + [new Date('2016-01')], + [new Date('2016-01-01')], + [new Date('2016-01-01:14:45:20')], + [new Date('Tue Feb 14 2017 14:45:20 GMT+0000 (GMT)')], + [new Date('nonsense')], + ]).it('returns true when given a date object of %s', (date) => { + expect(isDate(date)).to.be.true; + }); + + forEach([ + [100], + ['100'], + [false], + [{ a: 100 }], + [[100, 101, 102]], + [Date.parse('2016')], + [Date.now()], + ]).it('returns false when not given a date object of %s', (x) => { + expect(isDate(x)).to.be.false; + }); + }); + describe('.isEmpty', () => { describe('returns true', () => { it('when given an empty object', () => {