import fastify from 'fastify'; import assert from 'node:assert'; import test from 'node:test'; import { fastifyKitaHtml } from '../'; test('opts.autoDoctype', async (t) => { await using app = fastify(); app.register(fastifyKitaHtml); app.get('/default', () =>
Not a html root element
); app.get('/default/root', () => ); app.get('/html', (_, res) => res.html(
Not a html root element
)); app.get('/html/root', (_, res) => res.html()); await t.test('Default', async () => { const res = await app.inject({ method: 'GET', url: '/default' }); assert.strictEqual(res.statusCode, 200); assert.strictEqual(res.headers['content-type'], 'text/plain; charset=utf-8'); assert.strictEqual(res.body, '
Not a html root element
'); }); await t.test('Default root', async () => { const res = await app.inject({ method: 'GET', url: '/default/root' }); assert.strictEqual(res.statusCode, 200); assert.strictEqual(res.headers['content-type'], 'text/plain; charset=utf-8'); assert.strictEqual(res.body, ''); }); await t.test('Html ', async () => { const res = await app.inject({ method: 'GET', url: '/html' }); assert.strictEqual(res.statusCode, 200); assert.strictEqual(res.headers['content-type'], 'text/html; charset=utf-8'); assert.strictEqual(res.body, '
Not a html root element
'); }); await t.test('Html root', async () => { const res = await app.inject({ method: 'GET', url: '/html/root' }); assert.strictEqual(res.statusCode, 200); assert.strictEqual(res.headers['content-type'], 'text/html; charset=utf-8'); assert.strictEqual(res.body, ''); }); });