Add tests for byteSize

Uses a workaround and a custom Blob implementation, but it should work just fine.
This commit is contained in:
Angelos Chalaris
2018-02-07 16:36:31 +02:00
parent 674d4f94f0
commit 5d6e1f9abe
3 changed files with 21 additions and 7 deletions

View File

@ -1,10 +1,22 @@
const test = require('tape');
const byteSize = require('./byteSize.js');
// Custom implementation of Blob for the requirements of this snippet.
const Blob = class{
constructor(s) {
return {
size: Buffer.byteLength(s.toString())
};
}
}
// const byteSize = require('./byteSize.js');
// Override
const byteSize = str => new Blob([str]).size;
test('Testing byteSize', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof byteSize === 'function', 'byteSize is a Function');
t.equal(byteSize('a'), 1, 'Works for a single letter');
t.equal(byteSize('Hello World'), 11, 'Works for a common string');
t.equal(byteSize('😀'), 4, 'Works for emoji');
// Blob is not part of Node apparently?
//t.equal(byteSize('Hello World'), 11, 'Works for text');
//t.equal(byteSize('😀'), 4, 'Works for emojis');