# Angular Testing

> Angular testing patterns with Jest and TestBed. Covers unit tests for use cases, queries, services, and components using AAA pattern, mock repositories via InjectionToken, and signal-based component testing. Use when creating .spec.ts files, writing tests, or when the user mentions testing. ALWAYS use when generating test files.

- **Type:** Skill
- **Install:** `agentstack add skill-cuongtl1992-vibe-skills-angular-testing`
- **Verified:** Yes — security-reviewed for prompt injection and unsafe behavior
- **Seller:** [cuongtl1992](https://agentstack.voostack.com/s/cuongtl1992)
- **Installs:** 0
- **Category:** [Agent Skills](https://agentstack.voostack.com/c/agent-skills)
- **Latest version:** 0.1.0
- **License:** MIT
- **Upstream author:** [cuongtl1992](https://github.com/cuongtl1992)
- **Source:** https://github.com/cuongtl1992/vibe-skills/tree/main/skills/frontend/angular-testing

## Install

```sh
agentstack add skill-cuongtl1992-vibe-skills-angular-testing
```

Requires the [AgentStack CLI](https://agentstack.voostack.com/docs/cli). Works with Claude Code, Cursor, and any MCP-compatible agent.

## About

# Angular Testing Patterns

Jest + TestBed with AAA (Arrange/Act/Assert) pattern.

## Test File Location

Test files live next to the source file: `entity.service.ts` → `entity.service.spec.ts`

## Core Pattern: TestBed + InjectionToken Mocks

```typescript
import { TestBed } from '@angular/core/testing';

describe('CreateEntityUseCase', () => {
  let useCase: CreateEntityUseCase;
  let mockRepository: jest.Mocked;

  beforeEach(() => {
    mockRepository = {
      find: jest.fn(),
      findById: jest.fn(),
      create: jest.fn(),
      update: jest.fn(),
      delete: jest.fn(),
    };

    TestBed.configureTestingModule({
      providers: [
        CreateEntityUseCase,
        { provide: ENTITY_REPOSITORY, useValue: mockRepository },
        { provide: AuthService, useValue: { getCurrentUser: () => ({ id: 1 }) } },
      ],
    });

    useCase = TestBed.inject(CreateEntityUseCase);
  });

  it('should create entity successfully', async () => {
    // Arrange
    const request = { name: 'Test Entity' };
    const expected = { id: 1, name: 'Test Entity' };
    mockRepository.create.mockResolvedValue(Result.success(expected));

    // Act
    const result = await useCase.execute(request);

    // Assert
    expect(result.isSuccess).toBe(true);
    expect(result.value).toEqual(expected);
    expect(mockRepository.create).toHaveBeenCalled();
  });

  it('should return failure when name is empty', async () => {
    const result = await useCase.execute({ name: '' });
    expect(result.isFailure).toBe(true);
  });
});
```

## Signal Testing

```typescript
it('should update signal state', () => {
  const service = TestBed.inject(EntityListStateService);

  service.setKeyword('test');

  expect(service.keyword()).toBe('test');
  expect(service.page()).toBe(1); // reset on filter change
});
```

## Detailed Patterns

- UseCase/Query tests: [references/usecase-testing.md](references/usecase-testing.md)
- Component tests: [references/component-testing.md](references/component-testing.md)
- State service tests: [references/state-service-testing.md](references/state-service-testing.md)

## Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

- **Author:** [cuongtl1992](https://github.com/cuongtl1992)
- **Source:** [cuongtl1992/vibe-skills](https://github.com/cuongtl1992/vibe-skills)
- **License:** MIT

Install and usage instructions live in the source repository linked above.

## Pricing

- **Free** — Free

## Security capabilities

Automated source analysis of v0.1.0 — what this tool can access:

- **Network access:** no
- **Filesystem access:** no
- **Shell / process execution:** no
- **Environment & secrets:** no
- **Dynamic code execution:** no

*"Yes" means the capability is present in the source — more access means more to trust, not that it is unsafe.*


## Versions

- **0.1.0** — security scan: passed — Imported from the upstream source.

## Links

- Listing page: https://agentstack.voostack.com/l/skill-cuongtl1992-vibe-skills-angular-testing
- Seller: https://agentstack.voostack.com/s/cuongtl1992
- Browse the marketplace: https://agentstack.voostack.com/browse

---
Listed on AgentStack — the marketplace for AI agent skills and MCP servers. Every listing is security-reviewed. Creators keep 70%.
