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');

View File

@ -1,3 +1,2 @@
const converge = (converger, fns) => (...args) =>
converger(...fns.map(fn => fn.apply(null, args)));
const converge = (converger, fns) => (...args) => converger(...fns.map(fn => fn.apply(null, args)));
module.exports = converge;

View File

@ -1,4 +1,4 @@
Test log for: Wed Feb 07 2018 12:22:33 GMT+0200 (GTB Standard Time)
Test log for: Wed Feb 07 2018 16:35:36 GMT+0200 (GTB Standard Time)
> 30-seconds-of-code@0.0.1 test G:\My Files\git Repositories\30-seconds-of-code
> tape test/**/*.test.js | tap-spec
@ -88,6 +88,9 @@ Test log for: Wed Feb 07 2018 12:22:33 GMT+0200 (GTB Standard Time)
Testing byteSize
√ byteSize is a Function
√ Works for a single letter
√ Works for a common string
√ Works for emoji
Testing call
@ -1746,8 +1749,8 @@ Test log for: Wed Feb 07 2018 12:22:33 GMT+0200 (GTB Standard Time)
√ Works with multiple promises
total: 844
passing: 844
total: 847
passing: 847
duration: 2.4s