From 7f13958bdf9edfdebb723883902e75e5cda34bd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8A=B1=E8=A3=A4=E8=A1=A9?= <panfree23@gmail.com> Date: Tue, 5 May 2020 13:20:03 +0800 Subject: [PATCH] perf: refine code --- 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 423ab505..b22b2712 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 && time != null) { + 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 77ecb9d5..6b9703be 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', () => { @@ -24,4 +25,8 @@ describe('Utils:parseTime', () => { it('empty argument', () => { expect(parseTime()).toBeNull() }) + + it('null', () => { + expect(parseTime(null)).toBeNull() + }) })