Skip to content

Commit e3ce6db

Browse files
lxsmnsycatilafassina
authored andcommitted
Add form-data test
1 parent df68b5b commit e3ce6db

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

apps/tests/src/e2e/server-function.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,9 @@ test.describe("server-function", () => {
7272
await page.goto("http://localhost:3000/server-function-ping");
7373
await expect(page.locator("#server-fn-test")).toContainText('{"result":true}');
7474
});
75+
76+
test("should build with a server function w/ form data", async ({ page }) => {
77+
await page.goto("http://localhost:3000/server-form-data");
78+
await expect(page.locator("#server-fn-test")).toContainText('{"result":true}');
79+
});
7580
});
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { createEffect, createSignal } from "solid-js";
2+
3+
async function ping(value: FormData) {
4+
"use server";
5+
const file = value.get('example') as File;
6+
return await file.text();
7+
}
8+
9+
export default function App() {
10+
const [output, setOutput] = createSignal<{ result?: boolean }>({});
11+
12+
createEffect(async () => {
13+
const file = new File(['Hello, World!'], 'hello-world.txt');
14+
const formData = new FormData();
15+
formData.append('example', file);
16+
const result = await ping(formData);
17+
const value = await file.text();
18+
setOutput(prev => ({ ...prev, result: value === result }));
19+
});
20+
21+
return (
22+
<main>
23+
<span id="server-fn-test">{JSON.stringify(output())}</span>
24+
</main>
25+
);
26+
}

0 commit comments

Comments
 (0)