-
Notifications
You must be signed in to change notification settings - Fork 230
/
testing_test.ts
61 lines (54 loc) · 1.4 KB
/
testing_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
54
55
56
57
58
59
60
61
// Copyright 2018-2021 the oak authors. All rights reserved. MIT license.
import { assert, assertEquals, assertStrictEquals } from "./test_deps.ts";
import {
createMockApp,
createMockContext,
createMockNext,
mockContextState,
} from "./testing.ts";
Deno.test({
name: "testing - createMockApp()",
fn() {
const app = createMockApp();
assertEquals(app.state, {});
},
});
Deno.test({
name: "testing - createMockApp() - with state",
fn() {
const app = createMockApp({ a: "a" });
assertEquals(app.state, { a: "a" });
},
});
Deno.test({
name: "testing - createMockContext()",
fn() {
const ctx = createMockContext();
assert(ctx.app);
assertEquals(ctx.request.method, "GET");
assertStrictEquals(ctx.params, undefined);
assertEquals(ctx.request.url.pathname, "/");
assertEquals(ctx.state, {});
assertEquals(ctx.request.acceptsEncodings("identity"), "identity");
},
});
Deno.test({
name: "testing - mockContextState",
fn() {
mockContextState.encodingsAccepted = "gzip";
const ctx = createMockContext();
try {
assertEquals(ctx.request.acceptsEncodings("gzip"), "gzip");
} finally {
mockContextState.encodingsAccepted = "identity";
}
},
});
Deno.test({
name: "testing - createMockNext()",
fn() {
const next = createMockNext();
assertStrictEquals(typeof next, "function");
assert(next() instanceof Promise);
},
});