nestjs-testing-patterns

nestjs-testing-patterns is a skill for Claude Code from smicolon/ai-kit. It costs 35 tokens per session (734 once invoked), scanned A, original, MIT.

A guide to unit and integration testing for NestJS controllers, services, and guards. Unit tests check one part in isolation, while integration tests check how several parts work together.

In plain words
What is it for?
Use it to test NestJS business logic, controllers, guards, database-related services, and their interactions with dependencies.
Why use it?
It helps make backend tests repeatable by showing how to create a NestJS test module and replace real dependencies with mocks.

Skill for Claude Code

Written for Claude Code: shipped in a Claude Code plugin.

Needs its repository: it reads a path above its own folder, which exists only inside the repository. The line is import { User } from '../entities'.

Part of the nestjs plugin — 3 skills shipped together

Good fit Use it to test NestJS business logic, controllers, guards, database-related services, and their interactions with dependencies.

Compare 6 skills from other repositories ↓
Install

Getting it into your agent

It runs from inside its repository, so the clone comes first — what it calls does not travel with the file alone.

Clone the repo
git clone --depth 1 https://github.com/smicolon/ai-kit
agentmods
npx agentmods add skills/smicolon/ai-kit/nestjs-testing-patterns

Made for: Claude Code.

Or install nestjs, the plugin that ships this one along with the rest of its 3 skills.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for nestjs-testing-patterns

README.md
[![agentmods](https://agentmods.dev/badge/skills/smicolon/ai-kit/nestjs-testing-patterns/github.svg)](https://agentmods.dev/skills/smicolon/ai-kit/nestjs-testing-patterns)
Your own site
<a href="https://agentmods.dev/skills/smicolon/ai-kit/nestjs-testing-patterns"><img src="https://agentmods.dev/badge/skills/smicolon/ai-kit/nestjs-testing-patterns/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for nestjs-testing-patterns

Your own site · 80×15
<a href="https://agentmods.dev/skills/smicolon/ai-kit/nestjs-testing-patterns"><img src="https://agentmods.dev/badge/skills/smicolon/ai-kit/nestjs-testing-patterns.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 35 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 734 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00035 $0.00734
Opus 5 $0.00017 $0.00367
Sonnet 5 $0.00007 $0.00147
Haiku 4.5 $0.00003 $0.00073

Measured 5d ago against content hash 8faeb6181191, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-08, from the pricing page.

Security

Grade A, and why

nestjs-testing-patterns scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 5d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

packs/nestjs/skills/nestjs-testing-patterns/SKILL.md · 124 lines

How it starts

The opening of the file, as written. The whole thing — 124 lines — stays where its author put it; the contents beside it link to each section on GitHub.

NestJS Testing Patterns

Best practices for writing unit and integration tests in NestJS applications.

1. Service Unit Testing (Mocked Dependencies)

Test business logic in isolation by overriding providers with mocks:

import { Test, TestingModule } from '@nestjs/testing'
import { UsersService } from './users.service'
import { getRepositoryToken } from '@nestjs/typeorm'
import { User } from '../entities'

describe('UsersService', () => {
  let service: UsersService
  const mockUserRepository = {
    find: jest.fn(),
    findOneBy: jest.fn(),
    save: jest.fn(),
  }

  beforeEach(async () => {
    const module: TestingModule = await Test.createTestingModule({
      providers: [
        UsersService,
        {
          provide: getRepositoryToken(User),
          useValue: mockUserRepository,
        },
      ],
    }).compile()

    service = module.get<UsersService>(UsersService)
  })

  it('should find user by id', async () => {
    const expectedUser = { id: 'uuid-1', email: '[email protected]' }
    mockUserRepository.findOneBy.mockResolvedValue(expectedUser)

    const result = await service.findById('uuid-1')
    expect(result).toEqual(expectedUser)
    expect(mockUserRepository.findOneBy).toHaveBeenCalledWith({ id: 'uuid-1' })
  })
})

2. Controller Unit Testing

import { Test, TestingModule } from '@nestjs/testing'
import { UsersController } from './users.controller'
import { UsersService } from './users.service'

describe('UsersController', () => {
  let controller: UsersController
  const mockUsersService = {
    findAll: jest.fn().mockResolvedValue([]),
  }

  beforeEach(async () => {
    const module: TestingModule = await Test.createTestingModule({
      controllers: [UsersController],
      providers: [
        {
          provide: UsersService,
          useValue: mockUsersService,
        },
      ],
    }).compile()

    controller = module.get<UsersController>(UsersController)
  })

  it('should return an array of users', async () => {
    expect(await controller.findAll()).toEqual([])
  })
})

Read the full file on GitHub · 124 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 5d ago First seen · 124 lines · 35 tokens per session scan A 8faeb6181191

Subscribe to this mod's changes

nestjs-testing-patterns is a skill published in the GitHub repository smicolon/ai-kit (6 stars, last pushed 5d ago), licensed MIT. It adds 35 tokens to every session and 734 once invoked, about $0.0002 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-04.

Related

Other skills, from other repositories

backend-test

Generate backend tests (unit, integration, mocks) for existing code. Auto-invoke when user says "write test for", "add test", "test this", or "create test".

alekspetrov/navigator · 41 tokens

sync-new-data-type

Adds scaffolding for a new Sync data type in Chromium across protocol buffers, DataType definitions, feature flags, controller builders, unit tests, and metrics.

chromium/chromium · 36 tokens

generate-testability-wrappers

DO NOT USE when the target already consumes an injected interface or built-in abstraction such as IFileSystem or TimeProvider, even if the request says "generate a wrapper"; no new wrapper is needed. Use only when C# source calls an ambient/static dependency and no injectable seam exists: first-time TimeProvider…

dotnet/skills · 147 tokens

convex-test

Generate convex-test tests for the app's Convex functions.

openclaw/clawhub · 16 tokens

platform-apex-test-generate

Generate and validate Apex test classes with TestDataFactory patterns, bulk testing (251+ records), mocking strategies, assertion best practices, and disciplined test-fix loops. Use this skill when creating new Apex test classes, improving test coverage, debugging and fixing failing Apex tests, running test execution…

forcedotcom/sf-skills · 135 tokens

platform-apex-test-run

Apex test execution, coverage analysis, and test-fix loops with 120-point scoring. Use when the user needs to run Apex tests, check code coverage, fix failing tests, or work with Test.cls / Test.cls files. TRIGGER when: user runs Apex tests, checks code coverage, fixes failing tests, or touches Test.cls / Test.cls…

forcedotcom/sf-skills · 124 tokens