Add tests

From uxname/liteend · View interactive version

Add tests is an AI agent skill from the GitHub repository uxname/liteend. Write unit tests for an existing NestJS service, resolver, or controller in the project following its Vitest + NestJS Testing conventions.

How to use this skill

Skill file

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.

Test framework & setup

Steps

  1. Read the source file to understand its public methods, injected dependencies, and any guard/decorator usage
  2. Identify dependencies — note what is injected in the constructor (typically PrismaService, other services)
  3. Choose mock strategy:
  1. Write the spec file following the structure below
  2. Run tests to verify they pass:

```bash

npm test -- <path/to/file.spec.ts>

```

  1. If tests fail, read the error and fix — do NOT skip or comment out failing tests
  2. Run npm run check to verify the new test file passes linting and type checking.

Spec file structure

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 () => {
      // ...
    });
  });
});

What to test

Cover the following for each public method:

Do NOT write tests for:

Resolver-specific notes

Import style

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.