Skip to content

Commit c96e157

Browse files
committed
chore: add jsdom
Signed-off-by: Logan McAnsh <[email protected]>
1 parent 5b17629 commit c96e157

File tree

3 files changed

+378
-31
lines changed

3 files changed

+378
-31
lines changed

packages/form-data/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,11 @@
3636
"@remix-run/web-blob": "^3.0.4",
3737
"@remix-run/web-fetch": "^4.2.0",
3838
"@remix-run/web-file": "^3.0.2",
39+
"@types/jsdom": "^16.2.15",
3940
"@types/node": "15.0.2",
4041
"git-validate": "2.2.4",
4142
"husky": "^6.0.0",
43+
"jsdom": "^19.0.0",
4244
"lint-staged": "^11.0.0",
4345
"playwright-test": "^7.2.0",
4446
"prettier": "^2.3.0",

packages/form-data/test/form-data.spec.js

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { FormData } from "@remix-run/web-form-data";
22
import * as lib from "@remix-run/web-form-data";
33
import { File, Blob } from "@remix-run/web-file";
4+
import { JSDOM } from 'jsdom';
45
import { assert } from "./test.js";
56

67
/**
@@ -239,30 +240,6 @@ export const test = (test) => {
239240
assert.equal("blob", file.name);
240241
});
241242

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-
266243
test.skip("complicated form", () => {
267244
const data = new FormData();
268245
data.append("blobs", new Blob(["basic"]));
@@ -283,4 +260,39 @@ export const test = (test) => {
283260
"rename.md"
284261
);
285262
});
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+
})
286298
};

0 commit comments

Comments
 (0)