Skip to content
Myr

test(routing): add test cases for route grouping order (#640)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* Add test cases for route grouping * fix(validator): enable handling "Bad Request" in validator (#635) * feat(types): introduce `CustomHandler` interface (#637) * Fix nested test

authored by Jayden · committed by GitHub · parent 44eb4bb · Browse files · 1 file+64 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Co-authored-by: Yusuke Wada <yusuke@kamawada.com>

Diff stats

1 file+64 added−0 removed

  • tests:+64 added−0 removed

1 file+64 added−0 removed

modified:src/hono.test.ts+64 added
154 unmodified lines
155 expect(res.status).toBe(200)156 expect(await res.text()).toBe('post /user/register')157 })158159 describe('Grouped route', () => {160 let one: Hono, two: Hono, three: Hono161162 beforeEach(() => {163 one = new Hono()164 two = new Hono()165 three = new Hono()166 })167168 it('only works with correct order', async () => {169 three.get('/hi', (c) => c.text('hi'))170 two.route('/three', three)171 one.route('/two', two)172173 const { status } = await one.request('http://localhost/two/three/hi', { method: 'GET' })174 expect(status).toBe(200)175 })176177 it('fails with incorrect order 1', async () => {178 three.get('/hi', (c) => c.text('hi'))179 one.route('/two', two)180 two.route('/three', three)181 182 const { status } = await one.request('http://localhost/two/three/hi', { method: 'GET' })183 expect(status).toBe(404)184 })185186 it('fails with incorrect order 2', async () => {187 two.route('/three', three)188 three.get('/hi', (c) => c.text('hi'))189 one.route('/two', two)190 191 const { status } = await one.request('http://localhost/two/three/hi', { method: 'GET' })192 expect(status).toBe(404)193 })194195 it('fails with incorrect order 3', async () => {196 two.route('/three', three)197 one.route('/two', two)198 three.get('/hi', (c) => c.text('hi'))199 200 const { status } = await one.request('http://localhost/two/three/hi', { method: 'GET' })201 expect(status).toBe(404)202 })203204 it('fails with incorrect order 4', async () => {205 one.route('/two', two)206 three.get('/hi', (c) => c.text('hi'))207 two.route('/three', three)208 209 const { status } = await one.request('http://localhost/two/three/hi', { method: 'GET' })210 expect(status).toBe(404)211 })212213 it('fails with incorrect order 5', async () => {214 one.route('/two', two)215 two.route('/three', three)216 three.get('/hi', (c) => c.text('hi'))217 218 const { status } = await one.request('http://localhost/two/three/hi', { method: 'GET' })219 expect(status).toBe(404)220 })221 })222223 describe('Chained route', () => {224 const app = new Hono()225226 app
1041 unmodified lines