Skip to content

Commit

Permalink
fix: fix minMax plugin parsing empty array bug (#1062)
Browse files Browse the repository at this point in the history
  • Loading branch information
iamkun authored Oct 23, 2020
1 parent 48cbf31 commit 368108b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/plugin/minMax/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export default (o, c, d) => {
const sortBy = (method, dates) => {
if (!dates.length) {
return d()
if (!dates || !dates.length || !dates[0] || (dates.length === 1 && !dates[0].length)) {
return null
}
if (dates.length === 1 && dates[0].length > 0) {
[dates] = dates
Expand Down
19 changes: 15 additions & 4 deletions test/plugin/minMax.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,21 @@ const arg3 = dayjs('2017-01-01')
const arg4 = dayjs('Invalid Date')

it('Return current time if no argument', () => {
expect(dayjs.max().format())
.toBe(dayjs().format())
expect(dayjs.min().format())
.toBe(dayjs().format())
expect(dayjs.max())
.toBe(null)
expect(dayjs.min())
.toBe(null)
expect(dayjs.max(null))
.toBe(null)
expect(dayjs.min(null))
.toBe(null)
})

it('Return current time if passing empty array', () => {
expect(dayjs.max([]))
.toBe(null)
expect(dayjs.min([]))
.toBe(null)
})

it('Compare between arguments', () => {
Expand Down

0 comments on commit 368108b

Please sign in to comment.