Skip to content

Commit

Permalink
补充测试
Browse files Browse the repository at this point in the history
  • Loading branch information
LitoMore committed Jun 27, 2019
1 parent 5df59c1 commit 2fa2f70
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/libs/memoize.test.js
Original file line number Diff line number Diff line change
@@ -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)
})
4 changes: 4 additions & 0 deletions src/libs/parseFilename.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@ test('parseFilename', () => {
basename: 'abc',
extname: '.edf',
})
expect(parseFilename('abc')).toEqual({
basename: 'abc',
extname: '',
})
})

0 comments on commit 2fa2f70

Please sign in to comment.