Allow usage of iterable object in Blob constructor. (#108)

* Allow usage of iterable object in Blob constructor.

* Fix ESLint errors
This commit is contained in:
Nick K
2021-07-29 15:42:42 +02:00
committed by GitHub
parent 0b028432d0
commit c2903ca530
2 changed files with 39 additions and 3 deletions
+35
View File
@@ -36,6 +36,41 @@ test('Blob ctor parts', async t => {
t.is(await blob.text(), 'abcdefg[object Object]foo=');
});
test('Blob ctor threats an object with @@iterator as a sequence', async t => {
const blob = new Blob({[Symbol.iterator]: Array.prototype[Symbol.iterator]});
t.is(blob.size, 0);
t.is(await blob.text(), '');
});
test('Blob ctor reads blob parts from object with @@iterator', async t => {
const input = ['one', 'two', 'three'];
const expected = input.join('');
const blob = new Blob({
* [Symbol.iterator]() {
yield * input;
}
});
t.is(blob.size, new TextEncoder().encode(expected).byteLength);
t.is(await blob.text(), expected);
});
test('Blob ctor threats a string as a sequence', async t => {
const expected = 'abc';
const blob = new Blob(expected);
t.is(await blob.text(), expected);
});
test('Blob ctor threats Uint8Array as a sequence', async t => {
const input = [1, 2, 3];
const blob = new Blob(new Uint8Array(input));
t.is(await blob.text(), input.join(''));
});
test('Blob size', t => {
const data = 'a=1';
const blob = new Blob([data]);