index.test.ts
This file
Path
src/middleware/powered-by/index.test.ts
37 lines 路 1.2 KiB 路 TypeScript
Last changed by
chore: let oxfmt sort imports instead of eslint (#5442)Yusuke Wadabefore adoption859e2c2
History of this fileTake it
1234567891011121314151617181920212223242526272829303132333435363738import { poweredBy } from '.'import { Hono } from '../../hono'
describe('Powered by Middleware', () => { const app = new Hono()
app.use('/poweredBy/*', poweredBy()) app.get('/poweredBy', (c) => c.text('root'))
app.use('/poweredBy2/*', poweredBy()) app.use('/poweredBy2/*', poweredBy()) app.get('/poweredBy2', (c) => c.text('root'))
app.use('/poweredBy3/*', poweredBy({ serverName: 'Foo' })) app.get('/poweredBy3', (c) => c.text('root'))
it('Should return with X-Powered-By header', async () => { const res = await app.request('http://localhost/poweredBy') expect(res).not.toBeNull() expect(res.status).toBe(200) expect(res.headers.get('X-Powered-By')).toBe('Hono') })
it('Should not return duplicate values', async () => { const res = await app.request('http://localhost/poweredBy2') expect(res).not.toBeNull() expect(res.status).toBe(200) expect(res.headers.get('X-Powered-By')).toBe('Hono') })
it('Should return custom serverName', async () => { const res = await app.request('http://localhost/poweredBy3') expect(res).not.toBeNull() expect(res.status).toBe(200) expect(res.headers.get('X-Powered-By')).toBe('Foo') })})