Skip to content

Commit fb7a59c

Browse files
committed
Make time test deterministic
1 parent e5eb724 commit fb7a59c

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/detectFieldType.test.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
11
import { detectFieldType } from './DataSource';
2+
import { format } from 'date-fns';
23

34
test('years and months gets parsed as string to reduce false positives', () => {
45
expect(detectFieldType(['2005', '2006'])).toEqual(['string', ['2005', '2006']]);
56
expect(detectFieldType(['2005-01', '2006-01'])).toEqual(['string', ['2005-01', '2006-01']]);
67
});
78

9+
test('iso8601 date without time zone gets parsed as time', () => {
10+
const input = ['2005-01-02', '2006-01-02'];
11+
const res = detectFieldType(input);
12+
13+
expect(res[0]).toStrictEqual('time');
14+
15+
// Since the input doesn't have a time zone, the resulting timestamps are in
16+
// local time. For now, test that we can parse and format it to input values.
17+
expect(res[1].map(_ => format(_, 'yyyy-MM-dd'))).toStrictEqual(input);
18+
});
19+
820
test('iso8601 gets parsed as time', () => {
9-
expect(detectFieldType(['2005-01-02', '2006-01-02'])).toEqual(['time', [1104620400000, 1136156400000]]);
1021
expect(detectFieldType(['2006-01-02T15:06:13Z', '2006-01-02T15:07:13Z'])).toEqual([
1122
'time',
1223
[1136214373000, 1136214433000],

0 commit comments

Comments
 (0)