-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexample.ts
31 lines (28 loc) · 908 Bytes
/
example.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
import { makeFetch } from './mod.ts'
import { Handler } from './types.ts'
const handler: Handler = (req) => {
const url = new URL(req.url).pathname
if (url === '/') return new Response('hello')
else if (url === '/status') {
return new Response('teapot', { status: 418 })
} else if (url === '/header') {
return new Response('teapot', {
status: 418,
headers: { 'Coffee-Allowed': 'No' },
})
} else return new Response('Not Found', { status: 404 })
}
const fetch = makeFetch(handler)
for (const url of ['/', '/status', '/header']) {
const res = await fetch(url)
if (url === '/') {
res.expectStatus(200).expect('hello')
} else if (url === '/status') {
res.expect('teapot').expectStatus(418)
} else if (url === '/header') {
res.expect('Coffee-Allowed', 'No').expectStatus(418).expectHeader(
'Tea-Allowed',
null,
).expectBody('teapot')
}
}