encode.test.ts
This file
Path
src/utils/encode.test.ts
71 lines · 2.2 KiB · TypeScript
Last changed by
refactor(TypeScript): enable strict null check (#280)Yusuke Wadabefore adoptionb55eb2e
History of this fileTake it
refactor(TypeScript): enable strict null check (#280)Yusuke Wadabefore adoptionb55eb2e
line 1why, one step back1/* eslint-disable @typescript-eslint/ban-ts-comment */feat(jwt): export jwt utils (#187)Minghebefore adoption4f97c6d
lines 2–7why, one step back2import {3 utf8ToUint8Array,4 decodeBase64,5 encodeBase64,6 encodeBase64URL,7 decodeBase64URL,chore: absolute import to relative import (#228)Yusuke Wadabefore adoption6ddba47
line 8why, one step back8} from './encode'feat(jwt): jwt middleware (#169)Minghebefore adoption3ed40d5
lines 9–17why, one step back910describe('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(() => {refactor(TypeScript): enable strict null check (#280)Yusuke Wadabefore adoptionb55eb2e
line 18why, one step back18 // @ts-ignorefeat(jwt): jwt middleware (#169)Minghebefore adoption3ed40d5
lines 19–28why, one step back19 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(() => {refactor(TypeScript): enable strict null check (#280)Yusuke Wadabefore adoptionb55eb2e
line 29why, one step back29 // @ts-ignorefeat(jwt): jwt middleware (#169)Minghebefore adoption3ed40d5
lines 30–36why, one step back30 decodeBase64(null)31 }).toThrowError(TypeError)32 })33 })34 describe('base64url', () => {35 it('encodeBase64URL', () => {36 expect(encodeBase64URL('hooooooooo')).toBe('aG9vb29vb29vbw')feat: enable adding types for Env variables (#191)Yusuke Wadabefore adoption77b93ab
lines 37–39why, one step back37 expect(encodeBase64URL('http://github.com/honojs/hono')).toBe(38 'aHR0cDovL2dpdGh1Yi5jb20vaG9ub2pzL2hvbm8'39 )feat(jwt): jwt middleware (#169)Minghebefore adoption3ed40d5
lines 40–43why, one step back40 expect(encodeBase64URL('炎')).toBe('54KO')41 expect(encodeBase64URL('abcdef')).not.toBe('abcdedf')42 expect(encodeBase64URL('')).toBe('')43 expect(() => {refactor(TypeScript): enable strict null check (#280)Yusuke Wadabefore adoptionb55eb2e
line 44why, one step back44 // @ts-ignorefeat(jwt): jwt middleware (#169)Minghebefore adoption3ed40d5
lines 45–50why, one step back45 encodeBase64URL(null)46 }).toThrow(TypeError)47 })4849 it('decodeBase64URL', async () => {50 expect(decodeBase64URL('aG9vb29vb29vbw')).toBe('hooooooooo')feat: enable adding types for Env variables (#191)Yusuke Wadabefore adoption77b93ab
lines 51–53why, one step back51 expect(decodeBase64URL('aHR0cDovL2dpdGh1Yi5jb20vaG9ub2pzL2hvbm8')).toBe(52 'http://github.com/honojs/hono'53 )feat(jwt): jwt middleware (#169)Minghebefore adoption3ed40d5
lines 54–57why, one step back54 expect(decodeBase64URL('54KO')).toBe('炎')55 expect(decodeBase64URL('abcdedf')).not.toBe('abcdef')56 expect(decodeBase64URL('')).toBe('')57 expect(() => {refactor(TypeScript): enable strict null check (#280)Yusuke Wadabefore adoptionb55eb2e
line 58why, one step back58 // @ts-ignorefeat(jwt): jwt middleware (#169)Minghebefore adoption3ed40d5
lines 59–60why, one step back59 decodeBase64URL(null)60 }).toThrowError(TypeError)feat(jwt): export jwt utils (#187)Minghebefore adoption4f97c6d
lines 61–64why, one step back61 })62 })6364 describe('utf8ToUint8Array', () => {feat: enable adding types for Env variables (#191)Yusuke Wadabefore adoption77b93ab
line 65why, one step back65 it('should be equal', () => {feat(jwt): export jwt utils (#187)Minghebefore adoption4f97c6d
lines 66–68why, one step back66 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')feat(jwt): jwt middleware (#169)Minghebefore adoption3ed40d5
lines 69–71why, one step back69 })70 })71})