11import { expect } from "chai" ;
2- import { Component } from "../dist/index.js" ;
2+ import { Multipart , Component } from "../dist/index.js" ;
33
44describe ( "Component" , ( ) => {
55
@@ -35,7 +35,7 @@ describe("Component", () => {
3535 it ( "should parse headers and body correctly from Uint8Array" , ( ) => {
3636 const headers = "Content-Type: text/plain\r\nContent-Length: 5\r\n\r\n" ;
3737 const body = new Uint8Array ( [ 1 , 2 , 3 , 4 , 5 ] ) ;
38- const data = new Uint8Array ( [ ... headers . split ( "" ) . map ( c => c . charCodeAt ( 0 ) ) , ... body ] ) ;
38+ const data = Multipart . combineArrays ( [ new TextEncoder ( ) . encode ( headers ) , body ] ) ;
3939
4040 const component = Component . parse ( data ) ;
4141
@@ -45,8 +45,8 @@ describe("Component", () => {
4545 expect ( component . body ) . to . deep . equal ( body ) ;
4646 } ) ;
4747
48- it ( "should handle missing headers and body" , ( ) => {
49- const data = new Uint8Array ( [ 0x0D , 0x0A , 0x0D , 0x0A ] ) ;
48+ it ( "should handle missing headers and empty body" , ( ) => {
49+ const data = new Uint8Array ( [ 0x0D , 0x0A ] ) ;
5050
5151 const component = Component . parse ( data ) ;
5252
@@ -57,14 +57,25 @@ describe("Component", () => {
5757
5858 it ( "should handle headers with no body" , ( ) => {
5959 const headers = "Content-Type: text/plain\r\n\r\n" ;
60- const data = new Uint8Array ( [ ... headers . split ( "" ) . map ( c => c . charCodeAt ( 0 ) ) ] ) ;
60+ const data = new TextEncoder ( ) . encode ( headers ) ;
6161
6262 const component = Component . parse ( data ) ;
6363
6464 expect ( component . headers . get ( "Content-Type" ) ) . to . equal ( "text/plain" ) ;
6565
6666 expect ( component . body ) . to . deep . equal ( new Uint8Array ( 0 ) ) ;
6767 } ) ;
68+
69+ it ( "should handle body with no headers" , ( ) => {
70+ const body = "\r\nGoal: No headers!\r\n\r\nReally none.\r\n" ;
71+ const data = new TextEncoder ( ) . encode ( body ) ;
72+
73+ const component = Component . parse ( data ) ;
74+
75+ expect ( component . headers ) . to . be . empty ;
76+
77+ expect ( new TextDecoder ( ) . decode ( component . body ) ) . to . equal ( "Goal: No headers!\r\n\r\nReally none.\r\n" ) ;
78+ } ) ;
6879 } ) ;
6980
7081 describe ( "#bytes" , ( ) => {
0 commit comments