@@ -79,6 +79,22 @@ describe("Component", () => {
7979 } ) ;
8080 } ) ;
8181
82+ describe ( "blob" , ( ) => {
83+ it ( "should create Component from Blob with type" , async ( ) => {
84+ const blob = new Blob ( [ new Uint8Array ( [ 1 , 2 , 3 ] ) ] , { type : "text/plain" } ) ;
85+ const component = await Component . blob ( blob ) ;
86+ expect ( component . headers . get ( "Content-Type" ) ) . to . equal ( "text/plain" ) ;
87+ expect ( component . body ) . to . deep . equal ( new Uint8Array ( [ 1 , 2 , 3 ] ) ) ;
88+ } ) ;
89+
90+ it ( "should create Component from Blob without type" , async ( ) => {
91+ const blob = new Blob ( [ new Uint8Array ( [ 1 , 2 , 3 ] ) ] ) ;
92+ const component = await Component . blob ( blob ) ;
93+ expect ( component . headers . get ( "Content-Type" ) ) . to . equal ( null ) ;
94+ expect ( component . body ) . to . deep . equal ( new Uint8Array ( [ 1 , 2 , 3 ] ) ) ;
95+ } ) ;
96+ } ) ;
97+
8298 describe ( "#bytes" , ( ) => {
8399 it ( "should return the bytes of a Component with headers and body" , ( ) => {
84100 const headersInit = { "Content-Type" : "text/plain" , "Content-Length" : "3" } ;
@@ -97,4 +113,23 @@ describe("Component", () => {
97113 expect ( new TextDecoder ( ) . decode ( bytes ) ) . to . equal ( expected ) ;
98114 } ) ;
99115 } ) ;
116+
117+ describe ( "#blob" , ( ) => {
118+ it ( "should return the Blob of a Component with headers and body" , async ( ) => {
119+ const headersInit = { "Content-Type" : "text/plain" , "Content-Length" : "3" } ;
120+ const body = new Uint8Array ( [ 1 , 2 , 3 ] ) ;
121+ const component = new Component ( headersInit , body ) ;
122+ const blob = component . blob ( ) ;
123+ expect ( blob . type ) . to . equal ( "text/plain" ) ;
124+ expect ( await blob . bytes ( ) ) . to . deep . equal ( body ) ;
125+ } ) ;
126+
127+ it ( "should return the Blob of a Component with only headers" , async ( ) => {
128+ const headersInit = { "Content-Type" : "text/plain" , "Content-Length" : "3" } ;
129+ const component = new Component ( headersInit ) ;
130+ const blob = component . blob ( ) ;
131+ expect ( blob . type ) . to . equal ( "text/plain" ) ;
132+ expect ( await blob . bytes ( ) ) . to . deep . equal ( new Uint8Array ( 0 ) ) ;
133+ } ) ;
134+ } ) ;
100135} ) ;
0 commit comments