Skip to content

Unit test

According to Eden Treaty config and Unit Test, we may pass an Elysia instance to Eden Treaty directly to interact with the Elysia server directly without sending a network request.

We may use this pattern to create a unit test with end-to-end type safety and type-level tests all at once.

test/index.test.ts
import { describe, expect, it } from 'bun:test'
import { Elysia } from 'elysia'
import { treaty } from '@elysia/eden'
const app = new Elysia().get('/hello', 'hi')
const api = treaty(app)
describe('Elysia', () => {
it('returns a response', async () => {
const { data } = await api.hello.get()
expect(data).toBe('hi')
})
})

Include your test folder in tsconfig.json, then run TypeScript with the project’s compiler options.

Terminal window
bunx tsc --noEmit

This is useful to ensure type integrity for both client and server, especially during migrations.

Type to search the documentation.

    Up arrowDown arrow to navigateEnter to selectEscape to close