Use when nestJS testing with unit tests, integration tests, and e2e tests. Use when building well-tested NestJS applications.
View on GitHubTheBushidoCollective/han
jutsu-nestjs
January 24, 2026
Select agents to install to:
npx add-skill https://github.com/TheBushidoCollective/han/blob/main/jutsu/jutsu-nestjs/skills/nestjs-testing/SKILL.md -a claude-code --skill nestjs-testingInstallation paths:
.claude/skills/nestjs-testing/# 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