diff --git a/src/plugin/devHelper/index.js b/src/plugin/devHelper/index.js index 2f163a25f..68eaa18cf 100644 --- a/src/plugin/devHelper/index.js +++ b/src/plugin/devHelper/index.js @@ -12,7 +12,7 @@ export default (o, c, d) => { if (typeof date === 'number' && String(date).length === 4) { console.warn(`Guessing you may want to parse the Year ${date}, you should pass it as a String ${date}, not a Number. Otherwise, ${date} will be treated as a Unix timestamp`) } - if (cfg.args.length >= 2 && !d.p.customParseFormat) { + if (cfg.args.length >= 2 && typeof cfg.args[1] === 'string' && !d.p.customParseFormat) { console.warn(`To parse a date-time string like ${date} using the given format, you should enable customParseFormat plugin first. https://day.js.org/docs/en/parse/string-format`) } return oldParse.bind(this)(cfg) diff --git a/test/plugin/devHelper.test.js b/test/plugin/devHelper.test.js index ff63d434d..77dd51cc9 100644 --- a/test/plugin/devHelper.test.js +++ b/test/plugin/devHelper.test.js @@ -35,6 +35,12 @@ it('Warning Enable customParseFormat plugin while passing the second format para expect(consoleSpy).toHaveBeenCalledWith('To parse a date-time string like 2020 using the given format, you should enable customParseFormat plugin first. https://day.js.org/docs/en/parse/string-format') }) +it('Warning Enable customParseFormat plugin for date with format string (MM/DD/YYYY)', () => { + const consoleSpy = jest.spyOn(console, 'warn') + dayjs('11/1/2004', 'MM/DD/YYYY') + expect(consoleSpy).toHaveBeenCalledWith('To parse a date-time string like 11/1/2004 using the given format, you should enable customParseFormat plugin first. https://day.js.org/docs/en/parse/string-format') +}) + it('Warning: Setting locale before loading locale', () => { const consoleSpy = jest.spyOn(console, 'warn') dayjs.locale('zh-cn')