import { Hono } from 'hono' import { reactRenderer, useRequestContext } from '../src/react-renderer' const RequestUrl = () => { const c = useRequestContext() return <>{c.req.url} } describe('Basic', () => { const app = new Hono() app.use( // @ts-expect-error - `title` is not defined reactRenderer(({ children, title }) => { return ( {title} {children} ) }) ) app.get('/', (c) => { return c.render(

, { title: 'Title', } ) }) it('Should return HTML with layout', async () => { const res = await app.request('http://localhost/') expect(res).not.toBeNull() expect(res.status).toBe(200) expect(await res.text()).toBe( 'Title

http://localhost/

' ) }) it('Should return HTML without layout', async () => { const app = new Hono() app.use('*', reactRenderer()) app.get('/', (c) => c.render(

, { title: 'Title' } ) ) const res = await app.request('http://localhost/') expect(res).not.toBeNull() expect(res.status).toBe(200) expect(await res.text()).toBe('

http://localhost/

') }) it('Should return a default doctype', async () => { const app = new Hono() app.use( '*', reactRenderer( ({ children }) => { return ( {children} ) }, { docType: true } ) ) app.get('/', (c) => c.render(

Hello

, { title: 'Title' })) const res = await app.request('/') expect(res).not.toBeNull() expect(res.status).toBe(200) expect(await res.text()).toBe('

Hello

') }) it('Should return a custom doctype', async () => { const app = new Hono() app.use( '*', reactRenderer( ({ children }) => { return ( {children} ) }, { docType: '', } ) ) app.get('/', (c) => c.render(

Hello

, { title: 'Title' })) const res = await app.request('/') expect(res).not.toBeNull() expect(res.status).toBe(200) expect(await res.text()).toBe( '

Hello

' ) }) }) describe('Streaming', () => { it.skip('Vitest does not support Streaming') })