agentsclimarketplace

Nestjs testing

Skill DIYA73/nestjs-skills/nestjs-testing

8 Claude Code skills for NestJS backend development — module scaffolding, TypeORM, BullMQ queues, WebSocket gateways, JWT auth, Redis caching, Docker, and testing patterns.

Install
npx -y skills add DIYA73/nestjs-skills --skill nestjs-testing

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

2 things to look at

  • no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.
  • 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

What its author says it does

Copied from the file, not written here

Unit and e2e testing patterns for NestJS services, controllers, and gateways. Use when writing unit tests for a NestJS service or controller, writing e2e tests for API endpoints, or mocking TypeORM repositories or external services.

SKILL.md

3.2 KB, 727 tokens by cl100k_base, as published. Nobody here has run it

nestjs-testing

Unit and e2e testing patterns for NestJS services, controllers, and gateways.

Trigger

Use this skill when asked to:

  • Write unit tests for a NestJS service or controller
  • Write e2e tests for API endpoints
  • Mock TypeORM repositories or external services

Unit Test — Service

const mockRepo = {
  create: jest.fn(), save: jest.fn(), find: jest.fn(),
  findOne: jest.fn(), remove: jest.fn(), update: jest.fn(),
};

describe('UsersService', () => {
  let service: UsersService;

  beforeEach(async () => {
    const module = await Test.createTestingModule({
      providers: [
        UsersService,
        { provide: getRepositoryToken(User), useValue: mockRepo },
      ],
    }).compile();
    service = module.get<UsersService>(UsersService);
    jest.clearAllMocks();
  });

  it('returns user when found', async () => {
    const user = { id: '1', email: '[email protected]' } as User;
    mockRepo.findOne.mockResolvedValue(user);
    expect(await service.findOne('1')).toEqual(user);
  });

  it('throws NotFoundException when not found', async () => {
    mockRepo.findOne.mockResolvedValue(null);
    await expect(service.findOne('x')).rejects.toThrow(NotFoundException);
  });
});

Unit Test — Controller

const mockService = { findAll: jest.fn(), findOne: jest.fn(), create: jest.fn() };

describe('UsersController', () => {
  let controller: UsersController;

  beforeEach(async () => {
    const module = await Test.createTestingModule({
      controllers: [UsersController],
      providers: [{ provide: UsersService, useValue: mockService }],
    }).compile();
    controller = module.get<UsersController>(UsersController);
    jest.clearAllMocks();
  });

  it('findAll returns array', async () => {
    mockService.findAll.mockResolvedValue([{ id: '1' }]);
    expect(await controller.findAll()).toHaveLength(1);
  });
});

E2E Test

describe('UsersController (e2e)', () => {
  let app: INestApplication;

  beforeAll(async () => {
    const module = await Test.createTestingModule({ imports: [AppModule] }).compile();
    app = module.createNestApplication();
    app.useGlobalPipes(new ValidationPipe({ whitelist: true }));
    await app.init();
  });

  afterAll(async () => { await app.close(); });

  it('GET /users returns 401 without token', () => {
    return request(app.getHttpServer()).get('/api/v1/users').expect(401);
  });
});

Mock Patterns

// Redis
const mockRedis = {
  get: jest.fn().mockResolvedValue(null),
  set: jest.fn().mockResolvedValue('OK'),
  del: jest.fn().mockResolvedValue(1),
};

// Bull Queue
const mockQueue = { add: jest.fn().mockResolvedValue({ id: 'job-1' }) };
{ provide: getQueueToken('my-queue'), useValue: mockQueue }

Rules

  • Always jest.clearAllMocks() in beforeEach
  • Unit tests: mock ALL external dependencies
  • E2E tests: use real DB with .env.test
  • Test behavior, not implementation
  • Naming: it('returns 404 when user not found', ...)

What ships with it

Read from the repository

Just SKILL.md. No reference files, no scripts.

Keep looking

Skills are one crate of 328,083. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.