Skip to content

Commit 6646c3b

Browse files
SimenBcpojer
authored andcommitted
Add support for date in jest-get-type (#4621)
1 parent f264780 commit 6646c3b

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

packages/jest-get-type/src/__tests__/index.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@ describe('.getType()', () => {
2323
test('regexp', () => expect(getType(/abc/)).toBe('regexp'));
2424
test('map', () => expect(getType(new Map())).toBe('map'));
2525
test('set', () => expect(getType(new Set())).toBe('set'));
26+
test('date', () => expect(getType(new Date())).toBe('date'));
2627
});

packages/jest-get-type/src/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@ export type ValueType =
1919
| 'regexp'
2020
| 'map'
2121
| 'set'
22+
| 'date'
2223
| 'string'
2324
| 'symbol'
2425
| 'undefined';
2526

2627
// get the type of a value with handling the edge cases like `typeof []`
2728
// and `typeof null`
2829
const getType = (value: any): ValueType => {
29-
if (typeof value === 'undefined') {
30+
if (value === undefined) {
3031
return 'undefined';
3132
} else if (value === null) {
3233
return 'null';
@@ -47,6 +48,8 @@ const getType = (value: any): ValueType => {
4748
return 'map';
4849
} else if (value.constructor === Set) {
4950
return 'set';
51+
} else if (value.constructor === Date) {
52+
return 'date';
5053
}
5154
return 'object';
5255
// $FlowFixMe https://github.com/facebook/flow/issues/1015

0 commit comments

Comments
 (0)