encode.test.ts
This file
Path
src/utils/encode.test.ts
71 lines · 2.2 KiB · TypeScript
Last changed by
Not known.
History of this fileTake it
The walk stopped after 200 commits: lines older than 543fdba point at it.
fix(type): fix order of method overloading (#490)azukiazusa1before adoption543fdba
lines 1–71why, one step back1/* eslint-disable @typescript-eslint/ban-ts-comment */2import {3 utf8ToUint8Array,4 decodeBase64,5 encodeBase64,6 encodeBase64URL,7 decodeBase64URL,8} from './encode'910describe('encode', () => {11 describe('base64', () => {12 it('encodeBase64', () => {13 expect(encodeBase64('hooooooooo')).toBe('aG9vb29vb29vbw==')14 expect(encodeBase64('炎')).toBe('54KO')15 expect(encodeBase64('abcdef')).not.toBe('abcdedf')16 expect(encodeBase64('')).toBe('')17 expect(() => {18 // @ts-ignore19 encodeBase64(null)20 }).toThrow(TypeError)21 })2223 it('decodeBase64', async () => {24 expect(decodeBase64('aG9vb29vb29vbw==')).toBe('hooooooooo')25 expect(decodeBase64('54KO')).toBe('炎')26 expect(decodeBase64('abcdedf')).not.toBe('abcdef')27 expect(decodeBase64('')).toBe('')28 expect(() => {29 // @ts-ignore30 decodeBase64(null)31 }).toThrowError(TypeError)32 })33 })34 describe('base64url', () => {35 it('encodeBase64URL', () => {36 expect(encodeBase64URL('hooooooooo')).toBe('aG9vb29vb29vbw')37 expect(encodeBase64URL('http://github.com/honojs/hono')).toBe(38 'aHR0cDovL2dpdGh1Yi5jb20vaG9ub2pzL2hvbm8'39 )40 expect(encodeBase64URL('炎')).toBe('54KO')41 expect(encodeBase64URL('abcdef')).not.toBe('abcdedf')42 expect(encodeBase64URL('')).toBe('')43 expect(() => {44 // @ts-ignore45 encodeBase64URL(null)46 }).toThrow(TypeError)47 })4849 it('decodeBase64URL', async () => {50 expect(decodeBase64URL('aG9vb29vb29vbw')).toBe('hooooooooo')51 expect(decodeBase64URL('aHR0cDovL2dpdGh1Yi5jb20vaG9ub2pzL2hvbm8')).toBe(52 'http://github.com/honojs/hono'53 )54 expect(decodeBase64URL('54KO')).toBe('炎')55 expect(decodeBase64URL('abcdedf')).not.toBe('abcdef')56 expect(decodeBase64URL('')).toBe('')57 expect(() => {58 // @ts-ignore59 decodeBase64URL(null)60 }).toThrowError(TypeError)61 })62 })6364 describe('utf8ToUint8Array', () => {65 it('should be equal', () => {66 const k = 'a-secret-key'67 const arr = utf8ToUint8Array(k)68 expect(String(arr)).toEqual('97,45,115,101,99,114,101,116,45,107,101,121')69 })70 })71})