Skip to content

Commit 58e66cb

Browse files
committed
test: setup jsdom in caller file
Signed-off-by: Logan McAnsh <[email protected]>
1 parent adbee9d commit 58e66cb

File tree

3 files changed

+37
-37
lines changed

3 files changed

+37
-37
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
1+
import { JSDOM } from 'jsdom';
12
import { test as libTest } from "./form-data.spec.js"
23
import { test as fetchTest } from "./fetch.spec.js"
34
import { test } from "./test.js"
45

6+
7+
8+
test.before(() => {
9+
const { window } = new JSDOM('');
10+
// @ts-ignore
11+
global.window = window;
12+
global.document = window.document;
13+
global.navigator = window.navigator;
14+
global.getComputedStyle = window.getComputedStyle;
15+
})
16+
517
libTest(test)
618
fetchTest(test)
719
test.run()

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

Lines changed: 23 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
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';
54
import { assert } from "./test.js";
65

76
/**
87
* @param {import('./test').Test} test
98
*/
109
export const test = (test) => {
11-
test("test baisc", async () => {
10+
test("test basic", async () => {
1211
assert.equal(typeof FormData, "function");
1312
assert.isEqual(typeof lib.FormData, "function");
1413
});
@@ -261,38 +260,27 @@ export const test = (test) => {
261260
);
262261
});
263262

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-
})
263+
test("Should allow passing a form element", () => {
264+
const form = document.createElement("form");
265+
const insideInput = document.createElement("input");
266+
const outsideInput = document.createElement("input");
267+
268+
outsideInput.type = "text";
269+
outsideInput.name = "form";
270+
outsideInput.value = "outside";
271+
outsideInput.setAttribute("form", "my-form");
272+
273+
insideInput.type = "text";
274+
insideInput.name = "form";
275+
insideInput.value = "inside";
276+
277+
form.appendChild(insideInput);
278+
form.id = "my-form";
279+
280+
document.body.appendChild(form);
281+
document.body.appendChild(outsideInput);
282+
283+
const formData = new FormData(form);
284+
assert.equal(formData.getAll("form"), ["inside", "outside"]);
297285
})
298286
};

yarn.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,7 @@
656656
resolved "https://registry.yarnpkg.com/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.3.tgz#4ba8ddb720221f432e443bd5f9117fd22cfd4762"
657657
integrity sha512-sz7iLqvVUg1gIedBOvlkxPlc8/uVzyS5OwGz1cKjXzkl3FpL3al0crU8YGU1WoHkxn0Wxbw5tyi6hvzJKNzFsw==
658658

659-
659+
"@types/jsdom@^16.2.15":
660660
version "16.2.15"
661661
resolved "https://registry.npmjs.org/@types/jsdom/-/jsdom-16.2.15.tgz#6c09990ec43b054e49636cba4d11d54367fc90d6"
662662
integrity sha512-nwF87yjBKuX/roqGYerZZM0Nv1pZDMAT5YhOHYeM/72Fic+VEqJh4nyoqoapzJnW3pUlfxPY5FhgsJtM+dRnQQ==
@@ -4301,7 +4301,7 @@ jsbn@~0.1.0:
43014301
resolved "https://registry.yarnpkg.com/jsbn/-/jsbn-0.1.1.tgz#a5e654c2e5a2deb5f201d96cefbca80c0ef2f513"
43024302
integrity sha1-peZUwuWi3rXyAdls77yoDA7y9RM=
43034303

4304-
4304+
jsdom@^19.0.0:
43054305
version "19.0.0"
43064306
resolved "https://registry.npmjs.org/jsdom/-/jsdom-19.0.0.tgz#93e67c149fe26816d38a849ea30ac93677e16b6a"
43074307
integrity sha512-RYAyjCbxy/vri/CfnjUWJQQtZ3LKlLnDqj+9XLNnJPgEGeirZs3hllKR20re8LUZ6o1b1X4Jat+Qd26zmP41+A==

0 commit comments

Comments
 (0)