1
1
import { FormData } from "@remix-run/web-form-data" ;
2
2
import * as lib from "@remix-run/web-form-data" ;
3
3
import { File , Blob } from "@remix-run/web-file" ;
4
+ import { JSDOM } from 'jsdom' ;
4
5
import { assert } from "./test.js" ;
5
6
6
7
/**
@@ -239,30 +240,6 @@ export const test = (test) => {
239
240
assert . equal ( "blob" , file . name ) ;
240
241
} ) ;
241
242
242
- test ( "Allows passing a form element" , ( ) => {
243
- const form = document . createElement ( "form" ) ;
244
- const insideInput = document . createElement ( "input" ) ;
245
- const outsideInput = document . createElement ( "input" ) ;
246
-
247
- outsideInput . type = "text" ;
248
- outsideInput . name = "form" ;
249
- outsideInput . value = "outside" ;
250
- outsideInput . setAttribute ( "form" , "my-form" ) ;
251
-
252
- insideInput . type = "text" ;
253
- insideInput . name = "form" ;
254
- insideInput . value = "inside" ;
255
-
256
- form . appendChild ( insideInput ) ;
257
- form . id = "my-form" ;
258
-
259
- document . body . appendChild ( form ) ;
260
- document . body . appendChild ( outsideInput ) ;
261
-
262
- const formData = new FormData ( form ) ;
263
- assert . equal ( formData . getAll ( "form" ) , [ "inside" , "outside" ] ) ;
264
- } )
265
-
266
243
test . skip ( "complicated form" , ( ) => {
267
244
const data = new FormData ( ) ;
268
245
data . append ( "blobs" , new Blob ( [ "basic" ] ) ) ;
@@ -283,4 +260,39 @@ export const test = (test) => {
283
260
"rename.md"
284
261
) ;
285
262
} ) ;
263
+
264
+ test ( "Should allow passing a form element" , ( ) => {
265
+ test . before ( ( ) => {
266
+ const { window } = new JSDOM ( '<main></main>' ) ;
267
+ // @ts -ignore
268
+ global . window = window ;
269
+ global . document = window . document ;
270
+ global . navigator = window . navigator ;
271
+ global . getComputedStyle = window . getComputedStyle ;
272
+ } )
273
+
274
+ test ( "pass a form element" , ( ) => {
275
+ const form = document . createElement ( "form" ) ;
276
+ const insideInput = document . createElement ( "input" ) ;
277
+ const outsideInput = document . createElement ( "input" ) ;
278
+
279
+ outsideInput . type = "text" ;
280
+ outsideInput . name = "form" ;
281
+ outsideInput . value = "outside" ;
282
+ outsideInput . setAttribute ( "form" , "my-form" ) ;
283
+
284
+ insideInput . type = "text" ;
285
+ insideInput . name = "form" ;
286
+ insideInput . value = "inside" ;
287
+
288
+ form . appendChild ( insideInput ) ;
289
+ form . id = "my-form" ;
290
+
291
+ document . body . appendChild ( form ) ;
292
+ document . body . appendChild ( outsideInput ) ;
293
+
294
+ const formData = new FormData ( form ) ;
295
+ assert . equal ( formData . getAll ( "form" ) , [ "inside" , "outside" ] ) ;
296
+ } )
297
+ } )
286
298
} ;
0 commit comments