Skip to content

Commit

Permalink
fix: dayjs ConfigTypeMap add null & undefined (#1560)
Browse files Browse the repository at this point in the history
  • Loading branch information
imwh0im authored Jul 2, 2021
1 parent bfdab5c commit b5e40e6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 4 additions & 1 deletion test/parse.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,14 @@ describe('Parse', () => {
expect(ds.millisecond()).toEqual(ms.millisecond())
})

it('String Other, Null and isValid', () => {
it('String Other, Undefined and Null and isValid', () => {
global.console.warn = jest.genMockFunction()// moment.js otherString will throw warn
expect(dayjs('otherString').toString().toLowerCase()).toBe(moment('otherString').toString().toLowerCase())
expect(dayjs(undefined).toDate()).toEqual(moment(undefined).toDate())
expect(dayjs().isValid()).toBe(true)
expect(dayjs(undefined).isValid()).toBe(true)
expect(dayjs('').isValid()).toBe(false)
expect(dayjs(null).isValid()).toBe(false)
expect(dayjs('otherString').isValid()).toBe(false)
expect(dayjs(null).toString().toLowerCase()).toBe(moment(null).toString().toLowerCase())
})
Expand Down
2 changes: 1 addition & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ declare function dayjs (date?: dayjs.ConfigType, format?: dayjs.OptionType, loca

declare namespace dayjs {
interface ConfigTypeMap {
default: string | number | Date | Dayjs
default: string | number | Date | Dayjs | null | undefined
}

export type ConfigType = ConfigTypeMap[keyof ConfigTypeMap]
Expand Down

0 comments on commit b5e40e6

Please sign in to comment.