From 5890499077589db1c04c7a72c4dacaa97a58f87c Mon Sep 17 00:00:00 2001 From: cooper <1322849632@qq.com> Date: Tue, 5 May 2020 13:21:51 +0800 Subject: [PATCH] fix[parseTime]: fixed when pass null (#3038) --- src/utils/index.js | 2 +- tests/unit/utils/parseTime.spec.js | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/utils/index.js b/src/utils/index.js index eb760d5..96ee6e7 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -9,7 +9,7 @@ * @returns {string | null} */ export function parseTime(time, cFormat) { - if (arguments.length === 0) { + if (arguments.length === 0 || !time) { return null } const format = cFormat || '{y}-{m}-{d} {h}:{i}:{s}' diff --git a/tests/unit/utils/parseTime.spec.js b/tests/unit/utils/parseTime.spec.js index bc61d1a..3e138d0 100644 --- a/tests/unit/utils/parseTime.spec.js +++ b/tests/unit/utils/parseTime.spec.js @@ -1,4 +1,5 @@ import { parseTime } from '@/utils/index.js' + describe('Utils:parseTime', () => { const d = new Date('2018-07-13 17:54:01') // "2018-07-13 17:54:01" it('timestamp', () => { @@ -29,4 +30,8 @@ describe('Utils:parseTime', () => { it('empty argument', () => { expect(parseTime()).toBeNull() }) + + it('null', () => { + expect(parseTime(null)).toBeNull() + }) }) -- GitLab