Rules Hub
Code Ruleset
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)
A final absence assertion can pass even when the element never existed.
Objašnjenje (HR)
Završna provjera odsutnosti može proći i kada element nikada nije postojao.
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.
Notes (EN)
For a test claiming a state transition, establish the relevant initial state, perform the action and await the expected resulting state.
Exceptions / Tradeoffs (EN)
A fixture or preceding assertion can already establish the precondition; avoid duplicating checks unrelated to the behavior under test.