]> git.proxmox.com Git - mirror_novnc.git/blame - tests/test.base64.js
Use fat arrow functions `const foo = () => { ... };` for callbacks
[mirror_novnc.git] / tests / test.base64.js
CommitLineData
2b5f94fa 1const expect = chai.expect;
f8e9b9f1 2
dfae3209
SR
3import Base64 from '../core/base64.js';
4
f8e9b9f1
SR
5describe('Base64 Tools', function() {
6 "use strict";
7
2b5f94fa
JD
8 const BIN_ARR = new Array(256);
9 for (let i = 0; i < 256; i++) {
f8e9b9f1
SR
10 BIN_ARR[i] = i;
11 }
c464f47e 12
2b5f94fa 13 const B64_STR = "AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6PkJGSk5SVlpeYmZqbnJ2en6ChoqOkpaanqKmqq6ytrq+wsbKztLW2t7i5uru8vb6/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj5OXm5+jp6uvs7e7v8PHy8/T19vf4+fr7/P3+/w==";
f8e9b9f1
SR
14
15
16 describe('encode', function() {
17 it('should encode a binary string into Base64', function() {
2b5f94fa 18 const encoded = Base64.encode(BIN_ARR);
f8e9b9f1
SR
19 expect(encoded).to.equal(B64_STR);
20 });
21 });
22
23 describe('decode', function() {
24 it('should decode a Base64 string into a normal string', function() {
2b5f94fa 25 const decoded = Base64.decode(B64_STR);
f8e9b9f1
SR
26 expect(decoded).to.deep.equal(BIN_ARR);
27 });
28
29 it('should throw an error if we have extra characters at the end of the string', function() {
651c23ec 30 expect(() => Base64.decode(B64_STR+'abcdef')).to.throw(Error);
f8e9b9f1
SR
31 });
32 });
33});