Available since v0.1.0
[classlist=class:bool,...]
StablePresence/absence check on the element's class list. Format: comma-separated name:true|false pairs.
Syntax
fs-assert-<type>="<selector>[classlist=active:true]"
fs-assert-<type>="<selector>[classlist=active:true,hidden:false]"
fs-assert-<type>="<selector>[classlist=loading:false,ready:true,error:false]"
When to use it
- Class-based state machines —
.active,.selected,.completed,.expanded - Transition states —
.loadingshould flip to.ready - Error indicators —
.errorshould not be present after recovery - Anything that uses CSS classes as state flags
Example — toggle completion
<input type="checkbox"
fs-assert="todos/toggle-complete"
fs-trigger="change"
fs-assert-updated=".todo-item[classlist=completed:true]">
Passes when .todo-item has the completed class after the change event.
Example — transition state
<button fs-assert="data/load" fs-trigger="click"
fs-assert-updated=".data-panel[classlist=loading:false,ready:true]">
Reload
</button>
Passes when .data-panel is not loading AND is ready — both conditions must hold.
Semantics
- Checks
element.classList.contains(name). True means the class is present; false means it's not. - All entries must pass. A single failing entry means the whole modifier fails.
- Case-sensitive class names (matches DOM behavior).
trueandfalseare case-insensitive as values. Other values log a warning.
Pairs well with
fs-assert-updated— the canonical pairing for class togglesfs-assert-visible— verify visible class state- Dynamic assertion values — compute
!currentStatefor toggles
Gotchas
- Dynamic expected state with React/Vue/Svelte. For bidirectional toggles, compute the expected next state in the template:
[classlist=completed:${!todo.completed}]. Hardcodingcompleted:truebreaks as soon as the user untoggles. - CSS modules and scoped classes. Frameworks that generate hashed class names (CSS modules, Vue scoped styles) make
classlistchecks fragile. Prefer stable data attributes (data-state=open) for state signals. - Checking for a class that doesn't exist.
[classlist=neverpresent:false]passes trivially — the class is indeed not present. Be explicit about which classes matter and include all relevant ones.
See also
fs-assert-updated— the canonical pairing- Attribute checks — alternative for data-attribute state
- Modifiers index