Optionaloptions: TestAppOptions
Test application options
A started (or un-started) kernel application
// Hand-assembled: unit scope.
import { createTestApp } from '@setu-ts/testing';
import { RuntimePlugin } from '@setu-ts/runtime';
const app = await createTestApp({ plugins: [RuntimePlugin()] });
app.router.get('/users', (ctx) => ctx.response.json([{ id: 1 }]));
const res = await app.inject({ method: 'GET', url: '/users' });
console.log(res.statusCode); // 200
// Composition root: the real app, minus the database, plus a fake mailer.
import { createTestApp, overrideCapability } from '@setu-ts/testing';
import { CAPABILITIES } from '@setu-ts/common';
import { createApp } from '../setu.config.ts';
const app = await createTestApp({
app: createApp(),
without: ['database'],
overrides: [overrideCapability(CAPABILITIES.MAIL, fakeMailer)],
});
Creates a started test application that can be exercised via
inject()andfetch()without binding a socket.Two arms. Pass
pluginsto assemble one by hand, or passappto build from the project's own composition root and subtract from it — the latter is what keeps a test app's composition honest, since anything the root registers (error handling included) is present in the test too.