Skip to content
Myr

test(routing): add tests for routing without path (#1324)

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

authored by Yusuke Wada · committed by GitHub · parent 41ee5a1 · Browse files · 1 file+60 added−0 removed
This commit

State

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

Diff stats

1 file+60 added−0 removed

  • tests:+60 added−0 removed

1 file+60 added−0 removed

modified:src/hono.test.ts+60 added
76 unmodified lines
77 expect(res.status).toBe(404)78 })79})8081describe('Register handlers without a path', () => {82 describe('No basePath', () => {83 const app = new Hono()8485 app.get((c) => {86 return c.text('Hello')87 })8889 it('GET http://localhost/ is ok', async () => {90 const res = await app.request('/')91 expect(res.status).toBe(200)92 expect(await res.text()).toBe('Hello')93 })9495 it('GET http://localhost/anything is ok', async () => {96 const res = await app.request('/')97 expect(res.status).toBe(200)98 expect(await res.text()).toBe('Hello')99 })100 })101102 describe('With specifying basePath', () => {103 const app = new Hono().basePath('/about')104105 app.get((c) => {106 return c.text('About')107 })108109 it('GET http://localhost/about is ok', async () => {110 const res = await app.request('/about')111 expect(res.status).toBe(200)112 expect(await res.text()).toBe('About')113 })114115 it('GET http://localhost/ is not found', async () => {116 const res = await app.request('/')117 expect(res.status).toBe(404)118 })119 })120121 describe('With chaining', () => {122 const app = new Hono()123124 app.post('/books').get((c) => {125 return c.text('Books')126 })127128 it('GET http://localhost/books is ok', async () => {129 const res = await app.request('/books')130 expect(res.status).toBe(200)131 expect(await res.text()).toBe('Books')132 })133134 it('GET http://localhost/ is not found', async () => {135 const res = await app.request('/')136 expect(res.status).toBe(404)137 })138 })139})140141describe('router option', () => {142 it('Should be SmartRouter', () => {143 const app = new Hono()144 expect(app.router instanceof SmartRouter).toBe(true)
2149 unmodified lines