File tree 3 files changed +20
-11
lines changed
src/routes/actions/enhance
3 files changed +20
-11
lines changed Original file line number Diff line number Diff line change @@ -165,19 +165,22 @@ export function enhance(form_element, submit = () => {}) {
165
165
let result ;
166
166
167
167
try {
168
- const is_valid_enctype = enctype ?. match ( / a p p l i c a t i o n \/ x - w w w - f o r m - u r l e n c o d e d | m u l t i p a r t \/ f o r m | t e x t \/ p l a i n / ) ;
169
-
168
+ const is_valid_enctype = enctype ?. match (
169
+ / a p p l i c a t i o n \/ x - w w w - f o r m - u r l e n c o d e d | m u l t i p a r t \/ f o r m | t e x t \/ p l a i n /
170
+ ) ;
171
+
170
172
const headers = {
171
173
accept : 'application/json' ,
172
174
'Content-Type' : is_valid_enctype ? enctype : 'application/x-www-form-urlencoded' ,
173
175
'x-sveltekit-action' : 'true'
174
176
} ;
175
-
177
+
176
178
// @ts -expect-error
177
179
const body = enctype === 'multipart/form-data' ? form_data : new URLSearchParams ( form_data ) ;
178
-
179
- // @ts -expect-error
180
- if ( enctype === 'multipart/form-data' && headers [ 'Content-Type' ] ) delete headers [ 'Content-Type' ] ;
180
+
181
+ if ( enctype === 'multipart/form-data' && headers [ 'Content-Type' ] )
182
+ // @ts -expect-error
183
+ delete headers [ 'Content-Type' ] ;
181
184
182
185
const response = await fetch ( action , {
183
186
method : 'POST' ,
Original file line number Diff line number Diff line change 60
60
61
61
<form action =" ?/login" enctype =" application/x-www-form-urlencoded" method =" post" use:enhance >
62
62
<input class =" form-enctype-input" name =" username" type =" text" />
63
-
63
+
64
64
<button class =" form-enctype-submit" >Submit</button >
65
65
</form >
66
66
67
67
<form action =" ?/send_file" enctype =" multipart/form-data" method =" post" use:enhance >
68
- <input type =" file" name =" file" >
68
+ <input type =" file" name =" file" / >
69
69
70
70
<button class =" form-file-submit" type =" submit" >Submit</button >
71
71
</form >
Original file line number Diff line number Diff line change @@ -1153,7 +1153,9 @@ test.describe('Actions', () => {
1153
1153
await expect ( page . locator ( 'pre.formdata2' ) ) . toHaveText ( JSON . stringify ( { message : 'hello' } ) ) ;
1154
1154
} ) ;
1155
1155
1156
- test ( 'use:enhance with `enctype="application/x-www-form-urlencoded"` attribute in `<form>`' , async ( { page } ) => {
1156
+ test ( 'use:enhance with `enctype="application/x-www-form-urlencoded"` attribute in `<form>`' , async ( {
1157
+ page
1158
+ } ) => {
1157
1159
await page . goto ( '/actions/enhance' ) ;
1158
1160
1159
1161
expect ( await page . textContent ( 'pre.formdata1' ) ) . toBe ( JSON . stringify ( null ) ) ;
@@ -1176,8 +1178,12 @@ test.describe('Actions', () => {
1176
1178
await page . locator ( 'input[name="file"]' ) . setInputFiles ( './test-file.txt' ) ;
1177
1179
await page . locator ( 'button.form-file-submit' ) . click ( ) ;
1178
1180
1179
- await expect ( page . locator ( 'pre.formdata1' ) ) . toHaveText ( JSON . stringify ( { result : 'file name:test-file.txt' } ) ) ;
1180
- await expect ( page . locator ( 'pre.formdata2' ) ) . toHaveText ( JSON . stringify ( { result : 'file name:test-file.txt' } ) ) ;
1181
+ await expect ( page . locator ( 'pre.formdata1' ) ) . toHaveText (
1182
+ JSON . stringify ( { result : 'file name:test-file.txt' } )
1183
+ ) ;
1184
+ await expect ( page . locator ( 'pre.formdata2' ) ) . toHaveText (
1185
+ JSON . stringify ( { result : 'file name:test-file.txt' } )
1186
+ ) ;
1181
1187
await expect ( page . locator ( 'input[name=username].form-enctype-input' ) ) . toHaveValue ( '' ) ;
1182
1188
} ) ;
1183
1189
You can’t perform that action at this time.
0 commit comments