Skip to content

Commit 368108b

Browse files
authored
fix: fix minMax plugin parsing empty array bug (#1062)
1 parent 48cbf31 commit 368108b

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

src/plugin/minMax/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export default (o, c, d) => {
22
const sortBy = (method, dates) => {
3-
if (!dates.length) {
4-
return d()
3+
if (!dates || !dates.length || !dates[0] || (dates.length === 1 && !dates[0].length)) {
4+
return null
55
}
66
if (dates.length === 1 && dates[0].length > 0) {
77
[dates] = dates

test/plugin/minMax.test.js

+15-4
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,21 @@ const arg3 = dayjs('2017-01-01')
1818
const arg4 = dayjs('Invalid Date')
1919

2020
it('Return current time if no argument', () => {
21-
expect(dayjs.max().format())
22-
.toBe(dayjs().format())
23-
expect(dayjs.min().format())
24-
.toBe(dayjs().format())
21+
expect(dayjs.max())
22+
.toBe(null)
23+
expect(dayjs.min())
24+
.toBe(null)
25+
expect(dayjs.max(null))
26+
.toBe(null)
27+
expect(dayjs.min(null))
28+
.toBe(null)
29+
})
30+
31+
it('Return current time if passing empty array', () => {
32+
expect(dayjs.max([]))
33+
.toBe(null)
34+
expect(dayjs.min([]))
35+
.toBe(null)
2536
})
2637

2738
it('Compare between arguments', () => {

0 commit comments

Comments
 (0)