mirror of
https://github.com/honojs/hono.git
synced 2024-11-22 02:27:49 +01:00
fix(combine/every): make every
middleware work with short-circuiting middlewares (#3441)
This commit is contained in:
parent
ad0bba0964
commit
fe0a82a615
@ -150,6 +150,22 @@ describe('every', () => {
|
||||
expect(await res.text()).toBe('oops')
|
||||
expect(middleware2).not.toBeCalled()
|
||||
})
|
||||
|
||||
it('Should return the same response a middleware returns if it short-circuits the chain', async () => {
|
||||
const middleware1: MiddlewareHandler = async (c) => {
|
||||
return c.text('Hello Middleware 1')
|
||||
}
|
||||
const middleware2 = vi.fn(nextMiddleware)
|
||||
|
||||
app.use('/', every(middleware1, middleware2))
|
||||
app.get('/', (c) => {
|
||||
return c.text('Hello World')
|
||||
})
|
||||
const res = await app.request('http://localhost/')
|
||||
|
||||
expect(await res.text()).toBe('Hello Middleware 1')
|
||||
expect(middleware2).not.toBeCalled()
|
||||
})
|
||||
})
|
||||
|
||||
describe('except', () => {
|
||||
|
@ -94,6 +94,7 @@ export const every = (...middleware: (MiddlewareHandler | Condition)[]): Middlew
|
||||
if (res === false) {
|
||||
throw new Error('Unmet condition')
|
||||
}
|
||||
return res
|
||||
})
|
||||
|
||||
const handler = async (c: Context, next: Next) =>
|
||||
|
Loading…
Reference in New Issue
Block a user