chore(guidelines): add example difference between waitFor and waitUntil (#14992)

* chore(guidelines): add example difference between waitFor and waitUntil

Signed-off-by: Simon Rey <51708585+simonrey1@users.noreply.github.com>

* chore(guidelines): specify waitFor error

Signed-off-by: Simon Rey <51708585+simonrey1@users.noreply.github.com>

* chore(guidelines): apply suggestions

Signed-off-by: Simon Rey <51708585+simonrey1@users.noreply.github.com>

---------

Signed-off-by: Simon Rey <51708585+simonrey1@users.noreply.github.com>
This commit is contained in:
Simon Rey 2025-11-20 14:42:41 +01:00 committed by GitHub
parent d24881e522
commit f503b7248e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -187,6 +187,24 @@ const text = getByText('text in the page');
expect(text).toHaveStyle({ color: '#FFFFF'});
```
### `waitFor` vs `waitUntil`
Use `waitFor` (https://vitest.dev/api/vi.html#vi-waitfor) to retry an assertion until it passes, and `waitUntil` (https://vitest.dev/api/vi.html#vi-waituntil) to wait for a function to return a truthy value.
`waitFor` → needs an exception
`waitUntil` → needs a boolean
**Example:**
```typescript
// Use waitFor with an assertion
await waitFor(() => expect(get(providerInfos)).not.toHaveLength(0));
// Use waitUntil with a boolean value
await vi.waitUntil(() => get(imagesInfos).length > 0);
```
### Mocking a sub-component
To test a component in isolation without testing its sub-components, you have the possibility to mock