Back to Skills

nestjs-testing

verified

Use when nestJS testing with unit tests, integration tests, and e2e tests. Use when building well-tested NestJS applications.

View on GitHub

Marketplace

han

TheBushidoCollective/han

Plugin

jutsu-nestjs

Technique

Repository

TheBushidoCollective/han
60stars

jutsu/jutsu-nestjs/skills/nestjs-testing/SKILL.md

Last Verified

January 24, 2026

Install Skill

Select agents to install to:

Scope:
npx add-skill https://github.com/TheBushidoCollective/han/blob/main/jutsu/jutsu-nestjs/skills/nestjs-testing/SKILL.md -a claude-code --skill nestjs-testing

Installation paths:

Claude
.claude/skills/nestjs-testing/
Powered by add-skill CLI

Instructions

# NestJS Testing

Master testing in NestJS for building reliable applications with
comprehensive unit, integration, and end-to-end tests.

## Unit Testing Setup

Creating and configuring test modules with TestingModule.

```typescript
import { Test, TestingModule } from '@nestjs/testing';
import { UserService } from './user.service';
import { getRepositoryToken } from '@nestjs/typeorm';
import { User } from './entities/user.entity';

describe('UserService', () => {
  let service: UserService;
  let module: TestingModule;

  beforeEach(async () => {
    module = await Test.createTestingModule({
      providers: [
        UserService,
        {
          provide: getRepositoryToken(User),
          useValue: {
            find: jest.fn(),
            findOne: jest.fn(),
            save: jest.fn(),
            create: jest.fn(),
            delete: jest.fn(),
          },
        },
      ],
    }).compile();

    service = module.get<UserService>(UserService);
  });

  afterEach(async () => {
    await module.close();
  });

  it('should be defined', () => {
    expect(service).toBeDefined();
  });

  it('should find all users', async () => {
    const users = [{ id: 1, name: 'John' }];
    jest.spyOn(service, 'findAll').mockResolvedValue(users);

    const result = await service.findAll();
    expect(result).toEqual(users);
    expect(service.findAll).toHaveBeenCalled();
  });
});

// Custom provider testing
describe('ConfigService', () => {
  let service: ConfigService;

  beforeEach(async () => {
    const module = await Test.createTestingModule({
      providers: [
        {
          provide: ConfigService,
          useFactory: () => {
            return new ConfigService('.env.test');
          },
        },
      ],
    }).compile();

    service = module.get<ConfigService>(ConfigService);
  });

  it('should load config from test environment', () => {
    expect(service.get('NODE_ENV')).toBe('test');
  });
});
```

## Testing Controllers

Mocking services an

Validation Details

Front Matter
Required Fields
Valid Name Format
Valid Description
Has Sections
Allowed Tools
Instruction Length:
32685 chars