@@ -36,6 +36,41 @@ test('Blob ctor parts', async t => {
3636 t . is ( await blob . text ( ) , 'abcdefg[object Object]foo=' ) ;
3737} ) ;
3838
39+ test ( 'Blob ctor threats an object with @@iterator as a sequence' , async t => {
40+ const blob = new Blob ( { [ Symbol . iterator ] : Array . prototype [ Symbol . iterator ] } ) ;
41+
42+ t . is ( blob . size , 0 ) ;
43+ t . is ( await blob . text ( ) , '' ) ;
44+ } ) ;
45+
46+ test ( 'Blob ctor reads blob parts from object with @@iterator' , async t => {
47+ const input = [ 'one' , 'two' , 'three' ] ;
48+ const expected = input . join ( '' ) ;
49+
50+ const blob = new Blob ( {
51+ * [ Symbol . iterator ] ( ) {
52+ yield * input ;
53+ }
54+ } ) ;
55+
56+ t . is ( blob . size , new TextEncoder ( ) . encode ( expected ) . byteLength ) ;
57+ t . is ( await blob . text ( ) , expected ) ;
58+ } ) ;
59+
60+ test ( 'Blob ctor threats a string as a sequence' , async t => {
61+ const expected = 'abc' ;
62+ const blob = new Blob ( expected ) ;
63+
64+ t . is ( await blob . text ( ) , expected ) ;
65+ } ) ;
66+
67+ test ( 'Blob ctor threats Uint8Array as a sequence' , async t => {
68+ const input = [ 1 , 2 , 3 ] ;
69+ const blob = new Blob ( new Uint8Array ( input ) ) ;
70+
71+ t . is ( await blob . text ( ) , input . join ( '' ) ) ;
72+ } ) ;
73+
3974test ( 'Blob size' , t => {
4075 const data = 'a=1' ;
4176 const blob = new Blob ( [ data ] ) ;
0 commit comments