docs(auto-melhoria): componentes 56/56 + vitest pure DOM matchers + session state 00:52

This commit is contained in:
pulse-agent
2026-05-20 00:53:28 -03:00
parent 6dff4f8f48
commit 2f7db5fa10
4 changed files with 104 additions and 61 deletions
+56
View File
@@ -149,3 +149,59 @@ it('descrição', async () => {
- Tags: react, testing-library, hooks, async, vitest
- Pattern-Key: react.testing-library
- Recurrence-Count: 3
---
## [LRN-20260520-001] vitest-pure-dom-matchers
**Logged**: 2026-05-20T00:52:00-03:00
**Priority**: high
**Status**: applied
**Area**: testing
### Summary
Vitest jsdom puro — matchers nativos DOM valem mais que `@testing-library/jest-dom` para projetos pequenos
### Details
Problema: `@testing-library/jest-dom` não estava instalado. Erros \"Invalid Chai property: toHaveClass\" apareceram em 44 testes.
Solução aplicada: trocar todos os 56 testes de componentes para usar:
- `.classList.contains('bg-indigo-600')` ao invés de `.toHaveClass('bg-indigo-600')`
- `.getAttribute('id')` ao invés de `.toHaveAttribute('id', 'x')`
- `.textContent` / `container.querySelector()` ao invés de `screen.getByText()
- `tagName` ao invés de `getByRole('heading')`
Resultado: 56/56 testes verdes, 0 dependências extras.
### Suggested Action
Padronizar esta abordagem em todos os arquivos de teste. Só instalar `@testing-library/jest-dom` se surgir matcher que não dá para escrever com `.classList.contains()` nativo.
### Metadata
- Source: best_practice
- Tags: vitest, jsdom, testing, dom, pure-matchers
- Pattern-Key: vitest.pure-dom-matchers
- Recurrence-Count: 1
---
## [LRN-20260520-002] jsdom-fireEvent-writable-value
**Logged**: 2026-05-20T00:52:00-03:00
**Priority**: low
**Status**: workaround
**Area**: testing
### Summary
No jsdom, `value` de `<input>` não é writable — `fireEvent.change` não atualiza `input.value` diretamente
### Details
Worksaround: `Object.defineProperty(inp, 'value', { writable: true, value: 'abc' })` antes de `fireEvent.change(inp)`. Confirmado como solução mínima para testes de `onChange` em estruturas Tree AST plantes como jsdom.
### Suggested Action
Criar helper `test-utils.ts` com `setInputValue(el, val)` para encapsular o workaround.
### Metadata
- Source: error
- Tags: jsdom, fireEvent, input, value, onChange
- Pattern-Key: jsdom.fireEvent-change-writable
- Recurrence-Count: 1
+3
View File
@@ -13,4 +13,7 @@
| react.testing-library | 3 | 2026-05-19 | ✅ promoted → AGENTS.md |
| vitest.jsdom.mocks | 3 | 2026-05-19 | ✅ promoted → AGENTS.md |
| vitest.pure-dom-matchers | 1 | 2026-05-20 | tracking |
| jsdom.fireEvent-change-writable | 1 | 2026-05-20 | tracking |
_Quando Count >= 3 em >= 2 tarefas distintas em 30 dias → promover para AGENTS.md como skill/recomendacao permanente_