forked from elysiajs/elysia
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgeneration.test.ts
More file actions
58 lines (52 loc) · 1.27 KB
/
Copy pathgeneration.test.ts
File metadata and controls
58 lines (52 loc) · 1.27 KB
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
import { describe, it, expect } from 'bun:test'
import { Elysia } from '../src'
import { req, post } from './utils'
describe('code generation', () => {
it('process body', async () => {
const body = { hello: 'Wanderschaffen' }
const app = new Elysia()
.post('/1', ({ body }) => body)
.post('/2', function ({ body }) {
return body
})
.post('/3', (context) => {
return context.body
})
.post('/4', (context) => {
const c = context
const { body } = c
return body
})
.post('/5', (context) => {
const _ = context,
a = context
const { body } = a
return body
})
.post('/6', () => body, {
transform({ body }) {
// not empty
}
})
.post('/7', () => body, {
beforeHandle({ body }) {
// not empty
}
})
.post('/8', () => body, {
afterHandle({ body }) {
// not empty
}
})
const from = (number: number) =>
app.handle(post(`/${number}`, body)).then((r) => r.json())
expect(await from(1)).toEqual(body)
expect(await from(2)).toEqual(body)
expect(await from(3)).toEqual(body)
expect(await from(4)).toEqual(body)
expect(await from(5)).toEqual(body)
expect(await from(6)).toEqual(body)
expect(await from(7)).toEqual(body)
expect(await from(8)).toEqual(body)
})
})