Rules Hub
Coding Rules Library
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Assert both before and after the action to avoid trivially-passing tests
Check the pre-condition, perform the action, then check the post-condition so the test proves a real change.
Bad example
| 1 | test('item is hidden after collapse', async () => { |
| 2 | render(<Menu />); |
| 3 | collapse(); |
| 4 | // if the item was never rendered, this passes for the wrong reason |
| 5 | await expect.element(page.getByRole('link', { name: 'Latest' })).not.toBeVisible(); |
| 6 | }); |
Explanation (EN)
Only the end state is asserted. If the element was never present, the assertion passes even though the collapse logic does nothing, giving false confidence.
Objašnjenje (HR)
Provjerava se samo konacno stanje. Ako element nikad nije ni postojao, asercija prolazi iako logika sklapanja ne radi nista, sto daje laznu sigurnost.
Good example
| 1 | test('item is hidden after collapse', async () => { |
| 2 | render(<Menu />); |
| 3 | await expect.element(page.getByRole('link', { name: 'Latest' })).toBeVisible(); |
| 4 | collapse(); |
| 5 | await expect.element(page.getByRole('link', { name: 'Latest' })).not.toBeVisible(); |
| 6 | }); |
Explanation (EN)
Asserting visibility before collapsing confirms the starting state, so the final assertion genuinely proves the action toggled the element.
Objašnjenje (HR)
Provjera vidljivosti prije sklapanja potvrdjuje pocetno stanje, pa konacna asercija stvarno dokazuje da je akcija promijenila element.