Files
Xen-Orchestra-xen-orchestra…/@xen-orchestra/web/docs/tests.md
2026-11-09 09:57:02 +01:00

2.9 KiB

Testing

This guide documents the unit-testing conventions used in @xen-orchestra/web, as established across the pool, host and vm modules. Follow it when adding tests for a new module, composable, utility or component.

Start with Assert behaviour, not implementation — it is the rule the rest of this guide serves.

What to test first

A fixed priority, not a preference:

  1. Components that make up a page (modules/<mod>/components/**) — top priority, equal with the next entry
  2. Composables and utilities (*.composable.ts, *.util.ts) — top priority
  3. Pages (src/pages/**) — lowest, and deliberately thin: assert which components render, never their values

Testing a page is a different job from testing a component, and the component is the more valuable one. A component should not carry much complex logic — when it does, extract that into a composable or utility and test it there.

Only the app's own behaviour

An XO 6 test covers what the app decides, never what @xen-orchestra/web-core does on its own: a side panel opening on a selection, a store re-expanding on a resize, a select opening its options all belong to the web-core tests. A web-core component may be rendered beside the code under test when the app's rule depends on it, but the assertion must be about that rule: a test that still passes once the app's code is removed is testing web-core and is deleted, not written. A state the app sets on a web-core component (busy, disabled, selected, a table state…) is asserted through that component's props (getUiButton(wrapper, label).props('busy')), never through the DOM it renders for it; a user action clicks the real <button> (getButton(wrapper, label)). A composable member that only forwards to a web-core store gets no test of its own. Selects: see Testing components.

Getting started

Writing a test

What you are testing