/harness-claude:nestjs-testing-patternsfrom harness-claude
Unit, integration, and e2e test patterns for NestJS apps using Test.createTestingModule, jest mocks, supertest, and overrideProvider.
Claude never picks this skill on its own
Its frontmatter has no description. Without a description, Claude Code leaves it out of the list Claude chooses from. Typing /harness-claude:nestjs-testing-patterns still runs it.
What the skill costs in Claude's context, stage by stage
No description Claude Code can read, so Claude's list leaves it out: only you can start it.
SKILL.md joins the conversation and stays.
Test NestJS apps with Test.createTestingModule, jest mocks, supertest e2e, and overrideProvider
describe('UsersService', () => {
let service: UsersService;
let prisma: DeepMockProxy<PrismaClient>;
beforeEach(async () => {
const module = await Test.createTestingModule({
providers: [UsersService, { provide: PrismaService, useValue: mockDeep<PrismaClient>() }],
}).compile();
service = module.get(UsersService);
prisma = module.get(PrismaService);
});
it('throws NotFoundException when user does not exist', async () => {
prisma.user.findUnique.mockResolvedValue(null);
await expect(service.findOne('missing-id')).rejects.toThrow(NotFoundException);
});
});
describe('UsersController (integration)', () => {
let app: INestApplication;
let usersService: jest.Mocked<UsersService>;
beforeAll(async () => {
const module = await Test.createTestingModule({
controllers: [UsersController],
providers: [UsersService],
})
.overrideProvider(UsersService)
.useValue({ findOne: jest.fn(), create: jest.fn() })
.compile();
app = module.createNestApplication();
app.useGlobalPipes(new ValidationPipe({ whitelist: true, transform: true }));
await app.init();
usersService = module.get(UsersService);
});
afterAll(() => app.close());
it('GET /users/:id returns 200', async () => {
usersService.findOne.mockResolvedValue({ id: '1', email: '[email protected]' } as User);
return request(app.getHttpServer()).get('/users/1').expect(200);
});
});
// test/app.e2e-spec.ts
describe('AppController (e2e)', () => {
let app: INestApplication;
beforeAll(async () => {
const module = await Test.createTestingModule({
imports: [AppModule],
}).compile();
app = module.createNestApplication();
await app.init();
});
it('POST /users returns 201', () => {
return request(app.getHttpServer())
.post('/users')
.send({ email: '[email protected]', password: 'password123' })
.expect(201);
});
});
.overrideGuard(JwtAuthGuard).useValue({ canActivate: () => true })
NestJS testing is built on Jest, with @nestjs/testing providing Test.createTestingModule() which creates an isolated module context — no HTTP server, no port binding. Providers, guards, pipes, and interceptors can all be selectively replaced.
overrideProvider vs direct mock value: overrideProvider(Token).useValue(mock) replaces the registered provider in the module without changing the module definition. This is cleaner than passing mock values in providers because it works even when the token is registered in an imported module.
mockDeep from jest-mock-extended: Prisma's generated client is deeply nested. mockDeep<PrismaClient>() creates a deep mock where every method is a jest.fn(). Pair with { provide: PrismaService, useValue: mockDeep<PrismaClient>() }.
Guard overrides: overrideGuard(MyGuard).useValue({ canActivate: () => true }) bypasses the guard entirely. To test the guard itself, instantiate it directly and call canActivate() with a mock ExecutionContext.
app.init() vs app.listen(): For supertest, call app.init() — it sets up the application without starting a TCP server. supertest(app.getHttpServer()) binds directly to the HTTP handler.
Test isolation: Use beforeEach to recreate the module for unit tests (avoids state leakage between tests). Use beforeAll for e2e tests (app startup is expensive). Always call app.close() in afterAll to avoid open handle warnings.
https://docs.nestjs.com/fundamentals/testing
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
nestjs-testing, jest, supertest, unit-testing, integration-testing, e2e-testing
npx claudepluginhub intense-visions/harness-engineering --plugin harness-claudeRead when SKILL.md points to them.
793 skills in this plugin
/a11y-aria-patternsARIA Patterns> Apply ARIA roles, states, and properties correctly to enhance assistive technology support for custom widgets/a11y-color-contrastColor Contrast and Color Independence> Ensure sufficient color contrast ratios and never use color as the sole means of conveying information/a11y-form-patternsAccessible Form Patterns> Build accessible forms with proper labeling, grouped controls, inline validation, and clear error communicationOther plugins' skills for the same job