/tsed:tsed-testingfrom Ts.ED
Writes unit and integration tests for Ts.ED v8 apps using Vitest (Jest fallback). Covers PlatformTest.create/invoke/reset, provider mocking, inject(), request context, and SuperTest integration.
Ships in Ts.ED. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Build every tested class through the Ts.ED test injector. Never instantiate a DI-managed class (service, controller, middleware, interceptor, module) with new in a test: it bypasses injection, scopes, hooks and mocks.
Read the testing recipes for middleware, interceptor, request-context and stubbing examples. Depth: https://tsed.dev/docs/testing.md, https://tsed.dev/tutorials/vitest.md.
Install vitest unplugin-swc @swc/core @vitest/coverage-v8 (and supertest @types/supertest for integration tests). A project generated by tsed-cli already has this.
// vitest.config.mts
import swc from "unplugin-swc";
import {defineConfig} from "vitest/config";
export default defineConfig({
test: {globals: true, root: "./"},
plugins: [
swc.vite({
jsc: {
target: "es2022",
keepClassNames: true,
parser: {syntax: "typescript", decorators: true},
transform: {useDefineForClassFields: false, legacyDecorator: true, decoratorMetadata: true}
}
})
]
});
@Inject() property injection resolve to undefined.useDefineForClassFields: false; class fields would overwrite injected properties.ts-jest per https://tsed.dev/tutorials/jest.md. It is unstable with ESM; prefer Vitest for new projects.PlatformTest.create() (steps 3-4). Fast, no HTTP server.PlatformTest.bootstrap(Server) + SuperTest (step 5).import {inject} from "@tsed/di";
import {PlatformTest} from "@tsed/platform-http/testing";
import {afterEach, beforeEach, describe, expect, it} from "vitest";
import {UsersService} from "./UsersService.js";
describe("UsersService", () => {
beforeEach(() => PlatformTest.create());
afterEach(() => PlatformTest.reset());
it("should return the user", async () => {
const service = inject(UsersService);
expect(await service.findById("1")).toEqual({id: "1"});
});
});
PlatformTest.create(settings?) accepts any configuration key: PlatformTest.create({features: {beta: true}}) then read it with constant("features.beta").PlatformTest.get(Token) and inject(Token) return the shared instance. PlatformTest.injector is the InjectorService.inject from @tsed/di. @tsed/platform-http/testing only exports PlatformTest and FakeAdapter.DITest from @tsed/di offers the same create, invoke, get, reset.const repository = {findById: vi.fn().mockResolvedValue({id: "1"})};
const service = await PlatformTest.invoke<UsersService>(UsersService, [{token: UsersRepository, use: repository}]);
expect(await service.findById("1")).toEqual({id: "1"});
expect(repository.findById).toHaveBeenCalledWith("1");
PlatformTest.invoke(Token, [{token, use}]) builds a fresh instance with local mocks and runs $onInit. Always await it.describe: PlatformTest.create({imports: [{token: UsersRepository, use: repository}]}), then inject(UsersService).imports entries accept use, useClass, useFactory or useAsyncFactory. useValue is ignored there.{token: DbConnection, use: fakeDb}.await PlatformTest.invoke<UsersController>(UsersController, [...]) and call the handler method directly with plain arguments.vi.mock() a class file that the injector must still register.import {PlatformTest} from "@tsed/platform-http/testing";
import SuperTest from "supertest";
import {afterAll, beforeAll, describe, expect, it} from "vitest";
import {Server} from "../Server.js";
import {UsersController} from "./UsersController.js";
describe("UsersController", () => {
beforeAll(PlatformTest.bootstrap(Server, {mount: {"/rest": [UsersController]}}));
afterAll(PlatformTest.reset);
it("should call GET /rest/users/:id", async () => {
const request = SuperTest(PlatformTest.callback());
const response = await request.get("/rest/users/1").expect(200);
expect(response.body).toEqual({id: "1"});
});
});
PlatformTest.bootstrap() returns a function; pass it to beforeAll, or call it: await PlatformTest.bootstrap(Server)().@tsed/platform-express (or -koa, -fastify) in Server.ts or in the spec, or pass {adapter: PlatformExpress}.listen: true is passed. The environment is test and the logger level is off by default.@Configuration keys (only mount, scopes, logger are merged). Passing imports drops the Server's own imports.vi.spyOn(PlatformTest.get(UsersService), "findById").mockResolvedValue(...).Point to @tsed/testcontainers-mongo (https://tsed.dev/tutorials/mongoose.md) and the premium @tsedio/testcontainers-* packages (Postgres, Redis, Vault) listed in https://tsed.dev/docs/testing.md. Do not hand-roll container lifecycle code when a package exists.
PlatformTest.bootstrap: no adapter package was imported. Add import "@tsed/platform-express";.beforeEach(PlatformTest.create) passes Vitest's test context as settings. Write beforeEach(() => PlatformTest.create()).PlatformTest.reset leaks providers, hooks and mocks into the next file and keeps handles open.PlatformTest.invoke without await returns a promise; assertions then run on the promise.PlatformTest.inject([Token], cb) is deprecated. Use inject() or PlatformTest.invoke().context() need runInContext(PlatformTest.createRequestContext(), () => ...) from @tsed/di.PlatformTest.bootstrap per file in beforeAll, not beforeEach: bootstrapping the server per test is slow.@tsed/common; PlatformTest lives in @tsed/platform-http/testing.vitest.config uses unplugin-swc with decorators, legacyDecorator, decoratorMetadata and useDefineForClassFields: false.new on a DI-managed class anywhere in the specs; instances come from inject(), PlatformTest.get() or PlatformTest.invoke().PlatformTest.create/bootstrap has a matching PlatformTest.reset.{token, use} and are asserted with toHaveBeenCalledWith; success and error paths are covered.SuperTest(PlatformTest.callback()).What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub tsedio/tsed --plugin tsed13 skills in this plugin
/tsed-cliScaffolds Ts.ED v8 projects and generates files with the Ts.ED CLI v7, through its MCP server (tools set-workspace, init-project, list-templates, get-template, generate-file) or the tsed binary (tsed init, generate, template, add, run, update, dev, build). Use when creating a Ts.ED project, adding a controller, service, middleware, model, interceptor, pipe, decorator or custom template, when package.json has a "tsed" key or @tsed/cli, when a .templates/ directory exists, or on errors E_CWD_NOT_SET, E_PROJECT_NOT_INITIALIZED, E_TEMPLATE_UNKNOWN, E_ARGS_INVALID./tsed-configurationConfigure and bootstrap a Ts.ED v8 server - the @Configuration decorator or configuration() on the Server class, PlatformExpress/PlatformKoa/PlatformFastify.bootstrap, server options (mount, middlewares, httpPort, httpsPort, acceptMimes, logger, statics, views, responseFilters, imports), per-platform express/koa/fastify options, and @tsed/config sources (envs, dotenv, json, yaml). Use when editing Server.ts, index.ts or src/config, adding @tsed/config or the extends option, or reading settings with constant(), refValue(), @Constant, @Value or configuration().get()./tsed-controllersWrite Ts.ED v8 HTTP controllers and routes - @Controller paths and nested children, mounting through the `mount` configuration, verb decorators from @tsed/schema, parameter decorators from @tsed/platform-params, typed inputs, response decorators and custom endpoint decorators. Use when adding or fixing a REST endpoint, when a route returns 404 or is shadowed by another route, when @BodyParams/@QueryParams/@PathParams receive a plain object or the wrong type, or when working with @Returns, @Status, @Redirect, @View, @Hidden, @Req/@Res or useDecorators./tsed-diDeclare, inject and scope Ts.ED v8 providers and wire lifecycle hooks - @Injectable, @Module, @Controller, @Inject, the functional API (inject, injectMany, lazyInject, constant, refValue, injectable().factory/asyncFactory/class/value, injector, context, logger), ProviderScope, custom tokens, @tsed/hooks ($on, $emit, $asyncEmit, $alter) and request context. Use when writing services or modules with @tsed/di, fixing InjectionError, "Given token is undefined" or undefined injected properties, choosing a scope, adding $onInit/$onDestroy/$onReady, or replacing registerProvider and other deprecated DI APIs./tsed-docsLocates authoritative Ts.ED v8 documentation and API reference instead of guessing framework APIs. Routes a topic to the right tsed.dev page, its markdown twin, the llms.txt indexes (tsed.dev, cli.tsed.dev, logger.tsed.dev) and the sibling tsed-* skills. Use when working in a project that depends on @tsed/* packages and an import path, decorator (@Controller, @Injectable, @Returns), function (inject, injectable, configuration), option name or error message is uncertain, when an example imports from @tsed/common, or before answering any "how do I ... in Ts.ED" question./tsed-exceptionsHandle errors and shape responses in a Ts.ED v8 application with @tsed/exceptions, exception filters from @tsed/platform-exceptions and response filters from @tsed/platform-response-filter. Use when throwing BadRequest/NotFound/Unauthorized or a custom exception, customizing the JSON error payload, writing a @Catch filter, customizing the 404 ResourceNotFound page, wrapping all responses in an envelope with @ResponseFilter, documenting errors with @Returns(404, NotFound), or debugging responses such as "InternalServerError", AJV_VALIDATION_ERROR or a response filter that is never called.Other plugins' skills for the same job