Skip to content

Commit

Permalink
Add is date function
Browse files Browse the repository at this point in the history
  • Loading branch information
mattphillips committed Feb 14, 2017
1 parent a20da2c commit cc4b0e5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/utils/index.js
Original file line number Diff line number Diff line change
@@ -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';
28 changes: 27 additions & 1 deletion src/utils/index.spec.js
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down

0 comments on commit cc4b0e5

Please sign in to comment.