mirror of
https://github.com/zoriya/elysia.git
synced 2026-08-15 18:44:25 +00:00
It looks like the `route` context is returning `undefined` if the `aot=false`. This commit try to fix it by passing the `route` to `createDynamicHandler` Fix: [#898](https://github.com/elysiajs/elysia/issues/898)
57 lines
1.4 KiB
TypeScript
57 lines
1.4 KiB
TypeScript
import { describe, expect, it } from 'bun:test'
|
|
import { Elysia } from '../../src'
|
|
import { req } from '../utils'
|
|
|
|
describe('context', () => {
|
|
describe('return route', () => {
|
|
it('on aot=true', async () => {
|
|
const app = new Elysia().get('/hi/:id', ({ route }) => route)
|
|
const res = await app.handle(req('/hi/123')).then((x) => x.text())
|
|
expect(res).toBe('/hi/:id')
|
|
})
|
|
|
|
it('on aot=false', async () => {
|
|
const app = new Elysia({ aot: false }).get(
|
|
'/hi/:id',
|
|
({ route }) => route
|
|
)
|
|
const res = await app.handle(req('/hi/123')).then((x) => x.text())
|
|
expect(res).toBe('/hi/:id')
|
|
})
|
|
})
|
|
|
|
describe('early return on macros with route data', () => {
|
|
it('on aot=true', async () => {
|
|
const app = new Elysia()
|
|
.macro({
|
|
test: {
|
|
beforeHandle({ route }) {
|
|
return route
|
|
}
|
|
}
|
|
})
|
|
.get('/hi/:id', () => 'should not returned', {
|
|
test: true
|
|
})
|
|
const res = await app.handle(req('/hi/123')).then((x) => x.text())
|
|
expect(res).toBe('/hi/:id')
|
|
})
|
|
|
|
it('on aot=false', async () => {
|
|
const app = new Elysia({ aot: false })
|
|
.macro({
|
|
test: {
|
|
beforeHandle({ route }) {
|
|
return route
|
|
}
|
|
}
|
|
})
|
|
.get('/hi/:id', () => 'should not returned', {
|
|
test: true
|
|
})
|
|
const res = await app.handle(req('/hi/123')).then((x) => x.text())
|
|
expect(res).toBe('/hi/:id')
|
|
})
|
|
})
|
|
})
|