From addaa3ecf8b18ea0cacb67766a70fd0a0a07f59b Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Sat, 7 Oct 2017 09:42:19 +0200 Subject: [PATCH] Add support for date in jest-get-type --- packages/jest-get-type/src/__tests__/index.test.js | 1 + packages/jest-get-type/src/index.js | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/jest-get-type/src/__tests__/index.test.js b/packages/jest-get-type/src/__tests__/index.test.js index 62e310666848..25776b3b6c11 100644 --- a/packages/jest-get-type/src/__tests__/index.test.js +++ b/packages/jest-get-type/src/__tests__/index.test.js @@ -23,4 +23,5 @@ describe('.getType()', () => { test('regexp', () => expect(getType(/abc/)).toBe('regexp')); test('map', () => expect(getType(new Map())).toBe('map')); test('set', () => expect(getType(new Set())).toBe('set')); + test('date', () => expect(getType(new Date())).toBe('date')); }); diff --git a/packages/jest-get-type/src/index.js b/packages/jest-get-type/src/index.js index 258b98e6f5be..ba8c252602fc 100644 --- a/packages/jest-get-type/src/index.js +++ b/packages/jest-get-type/src/index.js @@ -19,6 +19,7 @@ export type ValueType = | 'regexp' | 'map' | 'set' + | 'date' | 'string' | 'symbol' | 'undefined'; @@ -26,7 +27,7 @@ export type ValueType = // get the type of a value with handling the edge cases like `typeof []` // and `typeof null` const getType = (value: any): ValueType => { - if (typeof value === 'undefined') { + if (value === undefined) { return 'undefined'; } else if (value === null) { return 'null'; @@ -47,6 +48,8 @@ const getType = (value: any): ValueType => { return 'map'; } else if (value.constructor === Set) { return 'set'; + } else if (value.constructor === Date) { + return 'date'; } return 'object'; // $FlowFixMe https://github.com/facebook/flow/issues/1015