Writing Tests
Learn how to use the TestCase class to write expressive integration tests.
Basic Usage
Extend your test files with TestCase to access helper methods.
typescript
import { TestCase } from "testingcanxjs";
import { describe, test } from "bun:test";
describe("User API", () => {
test("guest cannot access profile", async () => {
const api = new TestCase();
// Fluent assertion API
const response = await api.get("/api/user");
response.assertStatus(401);
});
});Authentication
Use the actingAs helper to mock authentication headers easily.
typescript
test("authenticated user can access profile", async () => {
const api = new TestCase();
// Simulate logged in user with a token
const response = await api.actingAs("fake-jwt-token").get("/api/user");
response.assertStatus(200);
// Verify response body
const data = await response.json();
expect(data.email).toBe("user@example.com");
});Making Requests
Supported HTTP methods:
api.get(url)api.post(url, body)api.put(url, body)api.delete(url)