Skip to content

Parallel tests without global resets ​

Use ordinary Vitest test.concurrent. Create a scope and container inside each test body. Virentia needs no test wrapper or runner-specific setup; a scope belongs to the test that creates it.

Step 1 / 3
test.concurrent("first", async () => {
const appScope = scope();
const container = document.createElement("div");
const unmount = render(() => <Counter id="same" />, container, { scope: appScope });
await unmount();
});

An ordinary Vitest test creates and passes its own scope. Virentia has no test wrapper.

Module-level staticModel declarations share units, not values. Equal IDs are safe in independent scopes. Ref attachments stay in their document; disposing one instance must not disconnect another test's computed propagation. Use separate documents too when your scenario depends on document-level state such as focus.

The example below creates both test scopes itself, changes a bound action and checks that the exact button and text node survive. Its finally waits for local teardown even if an assertion fails.

Isolation needs no global reset. Explicitly created models remain creator-owned; keep retains automatically created models, so dispose a retained instance when your test no longer needs it. See Vitest and lifecycle rules.

Complete example sources
ts
import { scoped } from "@virentia/core";
import { expect, test } from "vitest";
import { f, staticModel } from "@virentia/core/models";
import { action, component, h, render, scope } from "@virentia/ui";

const Model = staticModel({ data: { count: f.number(0) }, setup(self) {
  return { increment: action(() => { self.count.value++; }) };
} });
const Counter = component({ model: Model, view: (_props, self) =>
  h("button", { onClick: self.model.increment }, self.model.count) });

test.concurrent.each(["first", "second"])("preserves DOM in %s", async () => {
  const appScope = scope();
  const container = document.createElement("div");
  const unmount = render(() => h(Counter, { id: "same" }), container, { scope: appScope });
  try {
    const counter = scoped(appScope, () => Counter.model.get("same"))!;
    const before = container.querySelector("button")!;
    const text = [...before.childNodes].find((node) => node.nodeType === 3);
    await counter.increment();
    expect(container.querySelector("button")).toBe(before);
    expect(before.textContent).toBe("1");
    expect([...before.childNodes]).toContain(text);
  } finally { await unmount(); }
});