0
0
mirror of https://github.com/honojs/hono.git synced 2024-12-01 11:51:01 +01:00
hono/test/middleware.test.ts
Yusuke Wada 7dd486ad7b
feat: builtin middleware as sub module (#81)
# BREAKING CHANGES!!

Now, builtin middleware are not in main package. You can't use `Middleware.logger()` method. Call sub modules if needed:

```js
import { Hono } from 'hono'
import { poweredBy } from 'hono/powered-by'
import { logger } from 'hono/logger'

const app = new Hono()

app.use('*', poweredBy())
app.use('*', logger())
```

Closes: #80

---

* feat: builtin middleware as sub module

* fixed middleware

* Update readme

* Add types

* New gif
2022-02-01 22:15:00 +09:00

18 lines
511 B
TypeScript

import { Hono } from '../src/hono'
import { poweredBy } from '../src/middleware/powered-by/powered-by'
describe('Builtin Middleware', () => {
const app = new Hono()
app.use('*', poweredBy())
app.get('/', () => new Response('root'))
it('Builtin Powered By Middleware', async () => {
const req = new Request('http://localhost/')
const res = await app.dispatch(req)
expect(res).not.toBeNull()
expect(res.status).toBe(200)
expect(res.headers.get('X-Powered-By')).toBe('Hono')
})
})