UNPKG

737 BPlain TextView Raw
1import Hashids from '../lib/hashids'
2
3describe('encode types', () => {
4 // eslint-disable-next-line @typescript-eslint/no-explicit-any
5 const testParams = (...numbers: any[]) => {
6 const hashids = new Hashids()
7
8 const id = hashids.encode(...numbers)
9 const decodedNumbers = hashids.decode(id)
10 const encodedId = hashids.encode(decodedNumbers)
11
12 expect(id).toBeTruthy()
13 expect(encodedId).toBe(id)
14 }
15
16 test(`should encode 1, 2, 3`, () => {
17 testParams(1, 2, 3)
18 })
19
20 test(`should encode [1, 2, 3]`, () => {
21 testParams('1', '2', '3')
22 })
23
24 test(`should encode '1', '2', '3'`, () => {
25 testParams([1, 2, 3])
26 })
27
28 test(`should encode ['1', '2', '3']`, () => {
29 testParams(['1', '2', '3'])
30 })
31})