Nestjs Testing
ASecurityBuild a unit test module with the service under test and typed mocks for every dependency. Follow Arrange–Act–Assert and clear mocks after each test. ```ts const repo = { findById: jest.fn() } satisfies Pick<UserRepository, 'findById'>; const module = await Test.createTestingModule({ providers: [UsersService, { provide: UserRepository, useValue: repo }], }).compile(); const service = module.get(UsersService); afterEach(() => jest.clearAllMocks()); it('returns a user', async () => { repo.findB...
- 584 stars
- 0 votes
- 0 copies
- 2 views
- Added September 5, 2026
Security analysis
100/100Pro scans all 11 files and shows the line behind each finding
npx -y skills add HoangNguyen0403/agent-skills-standard --skill nestjs-testing --agent claude-codeAre you the author of Nestjs Testing?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/hoangnguyen0403-nestjs-testing-agent-skills-standard)Build a unit test module with the service under test and typed mocks for every dependency. Follow Arrange–Act–Assert and clear mocks after each test.
```ts
const repo = { findById: jest.fn() } satisfies Pick<UserRepository, 'findById'>;
const module = await Test.createTestingModule({
providers: [UsersService, { provide: UserRepository, useValue: repo }],
}).compile();
const service = module.get(UsersService);
afterEach(() => jest.clearAllMocks());
it('returns a user', async () => {
repo.findById.mockResolvedValue(user);
await expect(service.findById(user.id)).resolves.toEqual(user);
expect(repo.findById).toHaveBeenCalledWith(user.id);
});
```
Use public methods, avoid `any` and private-method tests, and declare only variables used by setup or assertions.
Files in this skill
- eval-1.baseline.md
- eval-1.with-skill.md
- eval-2.baseline.md
- eval-2.with-skill.md
- eval-3.baseline.md
- eval-3.with-skill.md
- trigger-1.md
- trigger-2.md
- trigger-3.md
- trigger-4.md
Attribution
Related skills
View all in development →Comments
Loading comments…
Newsletter
Get the weekly list of safe new skills, and the ones we pulled.