From 4a822b95d66e0ef6a6754c997e798d3fae6a9ce1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BD=98=E5=98=89=E6=99=A8?= Date: Thu, 4 Jun 2020 21:26:13 +0800 Subject: [PATCH] fix[parseTime]: fixed when pass null https://github.com/PanJiaChen/vue-element-admin/commit/5890499077589db1c04c7a72c4dacaa97a58f87c --- src/utils/index.js | 2 +- tests/unit/utils/parseTime.spec.js | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/utils/index.js b/src/utils/index.js index 61e7704..37ae434 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 d1ac0d8..56045af 100644 --- a/tests/unit/utils/parseTime.spec.js +++ b/tests/unit/utils/parseTime.spec.js @@ -28,4 +28,8 @@ describe('Utils:parseTime', () => { it('empty argument', () => { expect(parseTime()).toBeNull() }) + + it('null', () => { + expect(parseTime(null)).toBeNull() + }) })