Skip to content

hono-email makes it straightforward to test email output. Strict-mode errors already reject render(), so unsupported tags or unsafe CSS fail tests automatically. Warnings require a small amount of configuration if you want them to fail tests.

Pass onWarning: 'error' so render() throws when any warning is collected:

import { expect, test } from 'vitest'
import { render } from 'hono-email'
import WelcomeEmail from './welcome-email'
// Fail the test on any compatibility warning.
const renderEmail = (jsx: Parameters<typeof render>[0]) => render(jsx, { onWarning: 'error' })
test('welcome email renders without warnings', async () => {
await expect(renderEmail(<WelcomeEmail />)).resolves.toBeDefined()
})

Use onWarning: 'silent' to inspect result.warnings without console output:

test('welcome email has no warnings', async () => {
const { warnings } = await render(<WelcomeEmail />, { onWarning: 'silent' })
expect(warnings).toEqual([])
})

You can also pass a callback to route warnings into your own collector:

const collected: Warning[] = []
await render(<WelcomeEmail />, {
onWarning: (warning) => collected.push(warning),
})