From 2fa2f7022ee68ae627a8d3be5e1a224458ec5f29 Mon Sep 17 00:00:00 2001 From: LitoMore Date: Fri, 28 Jun 2019 01:16:56 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A5=E5=85=85=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/libs/memoize.test.js | 32 ++++++++++++++++++++++++++++++++ src/libs/parseFilename.test.js | 4 ++++ 2 files changed, 36 insertions(+) create mode 100644 src/libs/memoize.test.js diff --git a/src/libs/memoize.test.js b/src/libs/memoize.test.js new file mode 100644 index 0000000..3c0dcbf --- /dev/null +++ b/src/libs/memoize.test.js @@ -0,0 +1,32 @@ +import memoize from './memoize' + +test('no parameter', () => { + expect(() => { + memoize(() => 0) + }).toThrowError(/^fn 必须有且只有一个参数$/) +}) + +test('two parameters', () => { + expect(() => { + memoize((a, b) => a + b) + }).toThrowError(/^fn 必须有且只有一个参数$/) +}) + +test('memoize', () => { + const generateTimestamp = type => { + switch (type) { + case 'now': + return +new Date() + default: + return 0 + } + } + const memoizedGenerateTimestamp = memoize(generateTimestamp) + const expected = memoizedGenerateTimestamp('now') + expect(memoizedGenerateTimestamp('now')).toBe(expected) + + memoizedGenerateTimestamp.delete('now') + setTimeout(() => { + expect(memoizedGenerateTimestamp('now')).not.toBe(expected) + }, 1) +}) diff --git a/src/libs/parseFilename.test.js b/src/libs/parseFilename.test.js index 2796678..af33b57 100644 --- a/src/libs/parseFilename.test.js +++ b/src/libs/parseFilename.test.js @@ -5,4 +5,8 @@ test('parseFilename', () => { basename: 'abc', extname: '.edf', }) + expect(parseFilename('abc')).toEqual({ + basename: 'abc', + extname: '', + }) })