@@ -19,7 +19,30 @@ import {FormDataEncoder} from "./Encoder"
19
19
test ( "Has boundary string" , t => {
20
20
const encoder = new FormDataEncoder ( new FormData ( ) )
21
21
22
- t . true ( typeof encoder . boundary === "string" )
22
+ t . true ( "boundary" in encoder )
23
+ t . is ( typeof encoder . boundary , "string" )
24
+ } )
25
+
26
+ test ( "boundary property is read-only" , t => {
27
+ const encoder = new FormDataEncoder ( new FormData ( ) )
28
+
29
+ const { boundary : expected } = encoder
30
+
31
+ // @ts -expect-error
32
+ try { encoder . boundary = "some string" } catch { /* noop */ }
33
+
34
+ t . is ( encoder . boundary , expected )
35
+ } )
36
+
37
+ test ( "boundary property cannot be deleted" , t => {
38
+ const encoder = new FormDataEncoder ( new FormData ( ) )
39
+
40
+ const { boundary : expected } = encoder
41
+
42
+ // @ts -expect-error
43
+ try { delete encoder . boundary } catch { /* noop */ }
44
+
45
+ t . is ( encoder . boundary , expected )
23
46
} )
24
47
25
48
test ( "Accepts custom boundary as the second argument" , t => {
@@ -33,9 +56,33 @@ test("Accepts custom boundary as the second argument", t => {
33
56
test ( "Has content-type string" , t => {
34
57
const encoder = new FormDataEncoder ( new FormData ( ) )
35
58
59
+ t . true ( "contentType" in encoder )
60
+ t . is ( typeof encoder . contentType , "string" )
36
61
t . true ( encoder . contentType . startsWith ( "multipart/form-data; boundary=" ) )
37
62
} )
38
63
64
+ test ( "contentType property is read-only" , t => {
65
+ const encoder = new FormDataEncoder ( new FormData ( ) )
66
+
67
+ const { contentType : expected } = encoder
68
+
69
+ // @ts -expect-error
70
+ try { encoder . contentType = "application/json" } catch { /* noop */ }
71
+
72
+ t . is ( encoder . contentType , expected )
73
+ } )
74
+
75
+ test ( "contentType cannot be deleted" , t => {
76
+ const encoder = new FormDataEncoder ( new FormData ( ) )
77
+
78
+ const { contentType : expected } = encoder
79
+
80
+ // @ts -expect-error
81
+ try { delete encoder . contentType } catch { /* noop */ }
82
+
83
+ t . is ( encoder . contentType , expected )
84
+ } )
85
+
39
86
test ( "Has content-type string with custom boundary string" , t => {
40
87
const expected = "BoundaryString123"
41
88
@@ -47,6 +94,40 @@ test("Has content-type string with custom boundary string", t => {
47
94
)
48
95
} )
49
96
97
+ test ( "Has contentLength property" , async t => {
98
+ const encoder = new FormDataEncoder ( new FormData ( ) )
99
+
100
+ t . true ( "contentLength" in encoder )
101
+ t . is ( typeof encoder . contentLength , "string" )
102
+ t . is (
103
+ encoder . contentLength ,
104
+
105
+ await readStream ( encoder ) . then ( ( { length} ) => `${ length } ` )
106
+ )
107
+ } )
108
+
109
+ test ( "contentLength property is read-only" , t => {
110
+ const encoder = new FormDataEncoder ( new FormData ( ) )
111
+
112
+ const { contentLength : expected } = encoder
113
+
114
+ // @ts -expect-error
115
+ try { encoder . contentLength = String ( Date . now ( ) ) } catch { /* noop */ }
116
+
117
+ t . is ( encoder . contentLength , expected )
118
+ } )
119
+
120
+ test ( "contentLength property cannot be deleted" , t => {
121
+ const encoder = new FormDataEncoder ( new FormData ( ) )
122
+
123
+ const { contentLength : expected } = encoder
124
+
125
+ // @ts -expect-error
126
+ try { encoder . contentLength = String ( Date . now ( ) ) } catch { /* noop */ }
127
+
128
+ t . is ( encoder . contentLength , expected )
129
+ } )
130
+
50
131
test ( "Has correct headers" , async t => {
51
132
const encoder = new FormDataEncoder ( new FormData ( ) )
52
133
0 commit comments