一键导入
add-tests
Write unit tests for an existing NestJS service, resolver, or controller in the project following its Vitest + NestJS Testing conventions.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Write unit tests for an existing NestJS service, resolver, or controller in the project following its Vitest + NestJS Testing conventions.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Create an End-to-End (E2E) test for a REST controller or GraphQL resolver using Fastify injection.
Add a new BullMQ job queue to the project — processor, producer injection, module registration, Bull Board integration, and unit tests.
Run the full code quality pipeline (TypeScript + Biome + Knip), fix all issues, and clean up comments in changed code.
Create a git commit with all unstaged changes. Use this skill whenever the user asks to commit, make a commit, save changes to git, or says something like "commit this", "commit all changes". Always runs npm run check before committing and fixes any errors found.
Use this workflow to implement ANY new feature following Test-Driven Development strictly.
Guide through a full Prisma schema change workflow — edit schema, create migration, regenerate client, update affected services.
| name | add-tests |
| description | Write unit tests for an existing NestJS service, resolver, or controller in the project following its Vitest + NestJS Testing conventions. |
The user wants to write unit tests for one or more existing files in the project. They will provide the file path(s) to test.
npm test → vitest run with VITEST_TARGET=unit)<name>.spec.ts next to <name>.tsdescribe, it, expect, beforeEach, afterEach, vi are available globally (no need to import them, but some existing files do import from vitest — both styles work)@nestjs/testing Test.createTestingModule to wire up dependenciestest/utils/mocks.ts provides helpers:
mock<T>() — shallow mock (each property becomes a vi.fn())createPrismaMock() — deep mock for PrismaClientcreateProfileServiceMock() — deep mock for ProfileServicecreatePubSubMock() — shallow mock for Mercurius PubSubcreateJobMock() — deep mock for BullMQ JobcreateXxxMock() factories to this file when they would be reused across multiple spec filestest/utils/mocks.ts is outside src/, calculate the relative path carefully:
src/modules/<name>/<name>.service.spec.ts -> use ../../../test/utils/mockssrc/common/<name>/<name>.spec.ts -> use ../../../test/utils/mockssrc/infrastructure/<name>/<name>.spec.ts -> use ../../../test/utils/mocksPrismaService, other services)PrismaService: use createPrismaMock() or a targeted inline object with only the needed Prisma model methods as vi.fn()mockDeep<ServiceType>() via createXxxMock() from test/utils/mocks.ts, or inline { methodName: vi.fn() }JwtAuthGuard, RolesGuard): override with .overrideGuard(Guard).useValue({ canActivate: vi.fn().mockReturnValue(true) })npm test -- <path/to/file.spec.ts>
npm run check to verify the new test file passes linting and type checking.import { Test, TestingModule } from '@nestjs/testing';
import { <ClassName> } from './<name>';
import { PrismaService } from '@/common/prisma/prisma.service';
// import other deps as needed
describe('<ClassName>', () => {
let subject: <ClassName>;
const mockPrismaService = {
<modelName>: {
findUnique: vi.fn(),
update: vi.fn(),
// only mock methods actually used
},
};
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [
<ClassName>,
{ provide: PrismaService, useValue: mockPrismaService },
],
}).compile();
subject = module.get(<ClassName>);
});
afterEach(() => {
vi.clearAllMocks();
});
describe('<methodName>', () => {
it('should <description of the happy path>', async () => {
// arrange
mockPrismaService.<model>.<method>.mockResolvedValue(<fixture>);
// act
const result = await subject.<methodName>(<args>);
// assert
expect(result).toEqual(<expected>);
expect(mockPrismaService.<model>.<method>).toHaveBeenCalledWith(<args>);
});
it('should <description of error/edge case>', async () => {
// ...
});
});
});
Cover the following for each public method:
Record not found)pubSub.publish, queue jobs, external servicesDo NOT write tests for:
.overrideGuard() as shown abovecurrentUser directly as a plain object matching the Profile shape (not from a mock)filter function inline as a plain function (see profile.resolver.spec.ts for an example)@/ alias for all non-relative imports (maps to src/)@/@generated/prisma/client for Prisma model types