-
-
Notifications
You must be signed in to change notification settings - Fork 38
/
serve_jsx_test.ts
51 lines (50 loc) · 1.47 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
// Copyright 2019-2020 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 { serveJsx } from "./serve_jsx.ts";
import { pathResolver } from "./_util.ts";
import { group } from "./_test_util.ts";
group("serveJsx", (t) => {
const func = serveJsx(
pathResolver(import.meta)("./fixtures/public"),
(f) => import(f),
);
t.test("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 resp.text(),
'<html data-reactroot="">deno</html>',
);
});
t.test("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.test("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!",
);
});
});