cloudcmd/test/common/btoa.js
2019-01-13 20:55:42 +02:00

31 lines
605 B
JavaScript

'use strict';
const test = require('supertape');
const stub = require('@cloudcmd/stub');
const btoa = require('../../common/btoa');
test('btoa: browser', (t) => {
const btoaOriginal = global.btoa;
const str = 'hello';
global.btoa = stub();
btoa(str);
t.ok(global.btoa.calledWith(str), 'should call global.btoa');
t.end();
global.btoa = btoaOriginal;
});
test('btoa: node', (t) => {
const str = 'hello';
const expected = 'aGVsbG8=';
const result = btoa(str);
t.equal(result, expected, 'should encode base64');
t.end();
});