@cinnabun/testing
v0.0.13
Published
Testing utilities for Cinnabun. Bootstrap test apps with HTTP helpers and provider overrides.
Readme
@cinnabun/testing
Testing utilities for Cinnabun. Bootstrap test apps with HTTP helpers and provider overrides.
Installation
bun add -D @cinnabun/testing (or @cinnabun/core workspace:*)createTestApp
Full HTTP server on a random port with get, post, put, delete helpers:
import { describe, it, expect, afterEach } from "bun:test";
import { RestController, GetMapping } from "@cinnabun/core";
import { createTestApp, type TestApp } from "@cinnabun/testing";
describe("API", () => {
let app: TestApp;
afterEach(async () => {
await app.close();
});
it("GET /api returns JSON", async () => {
@RestController("/api")
class ApiController {
@GetMapping("/")
index() {
return { message: "Hello" };
}
}
app = await createTestApp({ controllers: [ApiController] });
const res = await app.get("/api");
expect(res.status).toBe(200);
expect(await res.json()).toEqual({ message: "Hello" });
});
});createTestingModule
DI-only bootstrap (no HTTP). Useful for unit testing services:
import { createTestingModule } from "@cinnabun/testing";
const { container, resolve } = await createTestingModule({
providers: [UserService, MockUserRepository],
overrides: [
{ provide: UserRepository, useValue: mockRepo },
],
});
const userService = resolve(UserService);mockProviders
Generate stub overrides for providers:
import { mockProviders } from "@cinnabun/testing";
const overrides = mockProviders(EmailService, NotificationService);
// Use with createTestingModule overridesLicense
MIT
