Skip to content

Commit

Permalink
test(combine): refactor test code
Browse files Browse the repository at this point in the history
  • Loading branch information
usualoma committed Feb 7, 2025
1 parent 97d0895 commit e0cf156
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions src/middleware/combine/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,19 +92,15 @@ describe('some', () => {
expect(await res.text()).toBe('oops')
})

it('Should not call skipped middleware even if next function throws an error', async () => {
it('Should not call skipped middleware even if an error is thrown', async () => {
const middleware1: MiddlewareHandler = async (c, next) => {
await next()
}
const middleware2 = vi.fn(() => true)

app.use('/', async (c) => {
await some(middleware1, middleware2)(c, () => {
throw new Error('Error in next function')
})
})
app.get('/', (c) => {
return c.text('Hello World')
app.use('/', some(middleware1, middleware2))
app.get('/', () => {
throw new Error('Error')
})
app.onError((_, c) => {
return c.text('oops')
Expand All @@ -115,17 +111,13 @@ describe('some', () => {
expect(await res.text()).toBe('oops')
})

it('Should not call skipped middleware even if next function throws an error with returning truthy value middleware', async () => {
it('Should not call skipped middleware even if an error is thrown with returning truthy value middleware', async () => {
const middleware1 = () => true
const middleware2 = vi.fn(() => true)

app.use('/', async (c) => {
await some(middleware1, middleware2)(c, () => {
throw new Error('Error in next function')
})
})
app.get('/', (c) => {
return c.text('Hello World')
app.use('/', some(middleware1, middleware2))
app.get('/', () => {
throw new Error('Error')
})
app.onError((_, c) => {
return c.text('oops')
Expand Down

0 comments on commit e0cf156

Please sign in to comment.