-
Notifications
You must be signed in to change notification settings - Fork 0
/
router_test.ts
39 lines (29 loc) · 1.09 KB
/
router_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
import { assertEquals } from 'https://deno.land/std@0.212.0/assert/mod.ts'
import { Router } from './router.ts'
const HOME_RESPONSE_TEXT = 'Home'
const NOW_RESPONSE_TEXT = 'Now'
const $404_RESPONSE_TEXT = '404'
Deno.test('Router', async (test_context) => {
const router = new Router()
await test_context.step('Add routes', () => {
router.get('/', () => new Response(HOME_RESPONSE_TEXT))
router.get('/now', () => new Response(NOW_RESPONSE_TEXT))
router.$404(() => new Response($404_RESPONSE_TEXT))
})
await test_context.step('Get routes', async () => {
const home_response_text =
await (await router.handle(new Request('https://example.com')))
.text()
assertEquals(home_response_text, HOME_RESPONSE_TEXT)
const now_response_text =
await (await router.handle(new Request('https://example.com/now')))
.text()
assertEquals(now_response_text, NOW_RESPONSE_TEXT)
})
await test_context.step('404 route', async () => {
const response_text =
await (await router.handle(new Request('https://example.com/404')))
.text()
assertEquals(response_text, $404_RESPONSE_TEXT)
})
})