angular-testing-patterns
Skill2 starsChanged 4 months agoMITView on GitHub
Padroes de teste para Angular standalone com Signals (Jasmine/Karma) e disciplina de TDD. Use ao escrever spec de componente ou service, mockar facade com signals, ou definir o que cobrir antes de implementar.
In this repository18 other files it gives its agents.
- agents/AGENTS.mdAGENTS.md
- ai-operating-protocolSkill
- angular-feature-architectureSkill
- angular-primeng-auditSkill
- angular-primeng-uiSkill
- commit-and-branch-conventionsSkill
- frontend-auth-bootstrapSkill
- generating-backend-moduleSkill
- generating-data-layerSkill
- generating-dumb-createSkill
- generating-dumb-editSkill
- generating-dumb-listSkill
- generating-smart-pageSkill
- monorepo-workspace-standardsSkill
- nestjs-api-standardsSkill
- prisma-migration-disciplineSkill
- rbac-security-auditorSkill
- shared-contracts-librarySkill
The file
Files
Padroes de Teste Angular
Ciclo TDD (obrigatorio para componente ou service novo)
- Red: escrever o teste antes do codigo de producao e conferir que ele falha pelo motivo certo (a implementacao nao existe, nao um erro de sintaxe).
- Green: escrever o minimo para o teste passar. Passou, para de adicionar logica.
- Refactor: remover duplicacao e melhorar nomes, mantendo os testes verdes.
Repetir por comportamento, nao por arquivo. Nunca escrever codigo de producao sem um teste falhando antes.
Backend: rodar a suite antes de subir o servidor local. Frontend: nao e obrigatorio antes do serve, mas a suite precisa estar verde antes de abrir PR.
Estrutura da spec
TestBed.configureTestingModulecom o componente standalone emimports.NoopAnimationsModuleem todo teste que renderiza componente de UI: sem isso, animacao gera flake intermitente.- Padrao AAA (Arrange, Act, Assert), sem misturar etapas dentro do mesmo bloco.
jasmine.createSpyObjpara service; facade mockada com signals reais.fixture.detectChanges()antes de qualquer assert sobre o template.- Ler signal com chamada:
component.items().
const facadeMock = {
items: signal<IProduct[]>([]),
isLoading: signal(false),
loadAll: jasmine.createSpy('loadAll'),
toggleCreateDialog: jasmine.createSpy('toggleCreateDialog'),
};Mock com signal real (e nao array estatico) e o que permite testar reatividade:
facadeMock.items.set([...]) seguido de detectChanges() verifica o render de verdade.
Assincronia
fakeAsync+tick()para fluxo baseado em Observable/timer.TestSchedulerquando o teste e sobre a forma do stream, nao sobre o resultado.await fixture.whenStable()para promise encadeada.
O que cobrir
- Estados da tela: vazio, carregando, com dados, erro.
- Emissao de output ao interagir: clicar em editar emite exatamente o item da linha.
- Render condicional nos dois ramos do
@if. - Formulario: submit bloqueado enquanto invalido; payload emitido no formato certo.
- Componente com
effect(): mudanca doinput()reflete no formulario.
O que nao cobrir
- Comportamento interno da biblioteca de UI (paginacao da tabela, animacao do dialog). Testar o uso, nao a lib.
- Metodo privado: se renomear quebra o teste, o teste esta acoplado demais.
- CSS e detalhe visual.
Armadilha de ambiente
Runner headless costuma exigir o caminho do Chrome em variavel de ambiente (CHROME_BIN).
Sem isso o comando de teste trava sem mensagem util. Conferir isso antes de suspeitar do teste.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

