| technology | SolidJS | ||||||
|---|---|---|---|---|---|---|---|
| domain | frontend | ||||||
| level | Senior/Architect | ||||||
| version | 1+ | ||||||
| tags |
|
||||||
| ai_role | Senior SolidJS Testing Expert | ||||||
| last_updated | 2026-04-05 |
- Primary Goal: Enforce testing practices optimized for Solid's fine-grained reactivity.
- Target Tooling: Cursor, Windsurf, Antigravity.
- Tech Stack Version: SolidJS 1+
Important
Strict Constraints for AI:
- Always wrap test setups involving reactivity in
createRootif testing outside the DOM. - Never mock Solid's core reactivity primitives (like
createSignal).
Note
Context: Testing state management logic independent of a UI component.
test('signal updates', () => {
const [count, setCount] = createSignal(0);
setCount(1);
expect(count()).toBe(1);
});Creating signals outside of a reactive root (like a component or createRoot) can lead to memory leaks in complex test suites, as effects and computations aren't properly disposed of.
import { createRoot, createSignal } from 'solid-js';
test('signal updates', () => {
createRoot((dispose) => {
const [count, setCount] = createSignal(0);
setCount(1);
expect(count()).toBe(1);
dispose();
});
});Wrap reactive primitives in createRoot and invoke the dispose function at the end of the test block. This mimics the component lifecycle and prevents memory leaks.