1
0
mirror of https://github.com/benjlevesque/short-sha.git synced 2025-12-06 01:37:51 +01:00
Files
short-sha/__tests__/shorten.test.ts
Benjamin LEVESQUE 9f96a4f558 short-sha
2020-03-09 22:00:34 +01:00

40 lines
997 B
TypeScript

import {shorten} from '../src/shorten'
test('normal case', () => {
expect(shorten('6e8dcce3fd71cfe9aca3e18c82255dd1e4052aa1', 7)).toBe('6e8dcce')
})
test('already short', () => {
expect(shorten('6e8dcce', 7)).toBe('6e8dcce')
})
test('too short', () => {
expect(() => shorten('6e8dcc', 7)).toThrowError('input is too short')
})
test('undefined', () => {
expect(() => shorten(undefined as any, 7)).toThrowError('sha must be defined')
})
test('null', () => {
expect(() => shorten(null as any, 7)).toThrowError('sha must be defined')
})
test('invalid length', () => {
expect(() =>
shorten('6e8dcce3fd71cfe9aca3e18c82255dd1e4052aa1', 'x' as any)
).toThrowError('length is invalid')
})
test('negative length', () => {
expect(() =>
shorten('6e8dcce3fd71cfe9aca3e18c82255dd1e4052aa1', -1)
).toThrowError('length is invalid')
})
test('zero length', () => {
expect(() =>
shorten('6e8dcce3fd71cfe9aca3e18c82255dd1e4052aa1', 0)
).toThrowError('length is invalid')
})