-
-
Notifications
You must be signed in to change notification settings - Fork 38
/
serve_jsx_test.ts
53 lines (51 loc) 路 1.56 KB
/
serve_jsx_test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright 2019 Yusuke Sakurai. All rights reserved. MIT license.
import { createRecorder } from "./testing.ts";
import {
assertEquals,
assertMatch,
assertThrowsAsync
} from "./vendor/https/deno.land/std/testing/asserts.ts";
import { runIfMain } from "./vendor/https/deno.land/std/testing/mod.ts";
import { serveJsx } from "./serve_jsx.ts";
import { pathResolver, readString } from "./util.ts";
import { it } from "./test_util.ts";
it("serveJsx", t => {
const func = serveJsx(pathResolver(import.meta)("./fixtures/public"), f =>
import(f)
);
t.run("basic", async () => {
const rec = createRecorder({
url: "/",
method: "GET"
});
await func(rec);
const resp = await rec.response();
assertEquals(resp.status, 200);
assertMatch(resp.headers.get("content-type"), /text\/html/);
assertEquals(
await readString(resp.body),
'<html data-reactroot="">deno</html>'
);
});
t.run("should throw if jsx file has no default export", async () => {
const rec = createRecorder({ url: "/empty", method: "GET" });
await assertThrowsAsync(
async () => {
await func(rec);
},
Error,
"jsx: jsx/tsx files served by serveJsx must has default export!"
);
});
t.run("should throw if default export is not function", async () => {
const rec = createRecorder({ url: "/not-component", method: "GET" });
await assertThrowsAsync(
async () => {
await func(rec);
},
Error,
"jsx: default export must be React component!"
);
});
});
runIfMain(import.meta);