Files
discordeno/packages/utils/tests/base64.spec.ts
H01001000 e9feaf42d4 test: add mocha
* chore: add typescript plugin

* test: add mocha

* test: add test to utils
2022-12-02 16:17:46 +08:00

29 lines
845 B
TypeScript

import { expect } from 'chai'
import { decode, encode } from '../src/base64.js'
describe('base64.ts', () => {
describe('encode', () => {
it('can encode string to base64', () => {
expect(encode('Man Ё𤭢')).to.be.equal('TWFuINCB8KStog==')
})
it('can encode Uint8Array to base64', () => {
expect(
encode(new Uint8Array([77, 97, 110, 32, 208, 129, 240, 164, 173, 162]))
).to.be.equal('TWFuINCB8KStog==')
})
it('can encode Buffer to base64', () => {
expect(
encode(Buffer.from([77, 97, 110, 32, 208, 129, 240, 164, 173, 162]))
).to.be.equal('TWFuINCB8KStog==')
})
})
describe('decode', () => {
it('can dencode string to Uint8Array', () => {
expect(new TextDecoder().decode(decode('TWFuINCB8KStog=='))).to.be.equal(
'Man Ё𤭢'
)
})
})
})