Skip to content
Skills Library
Programming · Testing

test-visual-contract

/test-visual-contract

Author @ydinjs/tproc-backed visual-contract tests (*.spec.browser.test.ts) for @ydinjs/material-x components — assert that the rendered custom element agrees with the tokens tproc selected, using independent browser observations rather than circular token-vs-token comparisons. Use when writing a spec-contract test, adding a token contract to the bridge, or building a normalization adapter. For general behavior tests, the DoD checklist, or file routing, use the test-component skill instead.

Repository
material-x ↗
Licence
Apache-2.0
Last repository change
28.09.2026

Assessment and security

100/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content35 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
1
Scripts
0
HTML comments
0
URLs in SKILL.md
0
Deprecation

No signals detected. Repository changed on 28.09.2026, without references to retired models or APIs.

Licence

Apache-2.0, otwarta: można używać i zmieniać, z zachowaniem licencji i informacji o zmianach.

What it does and when to use it

Author @ydinjs/tproc-backed visual-contract tests (*.spec.browser.test.ts) for @ydinjs/material-x components — assert that the rendered custom element agrees with the tokens tproc selected, using independent browser observations rather than circular token-vs-token comparisons. Use when writing a spec-contract test, adding a token contract to the bridge, or building a normalization adapter. For general behavior tests, the DoD checklist, or file routing, use the test-component skill instead.

Original author description

Author @ydinjs/tproc-backed visual-contract tests (*.spec.browser.test.ts) for @ydinjs/material-x components — assert that the rendered custom element agrees with the tokens tproc selected, using independent browser observations rather than circular token-vs-token comparisons. Use when writing a spec-contract test, adding a token contract to the bridge, or building a normalization adapter. For general behavior tests, the DoD checklist, or file routing, use the test-component skill instead.

How it works

  1. The one rule that makes this layer worth having
  2. The bridge: getting tproc values into the browser
  3. effective vs. state
  4. Fail loudly — never let a missing oracle become a skipped assertion
  5. Bindings carry semantics, not values
  6. Normalization: centralize when shared, inline when local
  7. Derived values are named formulas, not copied results
  8. Non-token literals need provenance
  9. What a passing contract does and does not prove
  10. Validating or debugging the upstream source
Original SKILL.md headings · 92 lines, 946 words
SKILL.md preview
---
name: test-visual-contract
description: Author @ydinjs/tproc-backed visual-contract tests (*.spec.browser.test.ts) for @ydinjs/material-x components — assert that the rendered custom element agrees with the tokens tproc selected, using independent browser observations rather than circular token-vs-token comparisons. Use when writing a spec-contract test, adding a token contract to the bridge, or building a normalization adapter. For general behavior tests, the DoD checklist, or file routing, use the test-component skill instead.
---

# Authoring @ydinjs/tproc-backed visual contracts

A visual-contract test proves the _rendered_ component agrees with the `@ydinjs/tproc` tokens selected for it. It is the `*.spec.browser.test.ts` layer. Reference implementation: `packages/material-x/tests/button/button.spec.browser.test.ts` — read it before writing a new one.

Rationale (four-layer model, oracle hierarchy, what this layer does and does not prove) lives in `.agents/docs/test-architecture.md`. This skill is the _how_.

## The one rule that makes this layer worth having

**Never compare two forms of the same generated value.** This is circular and proves only that tproc emitted its own value:

```ts
// WRONG — reads back the custom property tproc itself generated
expect(getComputedStyle(host).getPropertyValue('--_container-height')).toBe(
  expectedContainerHeight,
);
```

A valid contract compares the tproc expectation against an **independent browser observation** — geometry or a computed style the browser resolved on its own:

```ts
// RIGHT — DOMRect is the browser's own measurement, not a token read-back
expect(implementation.getBoundingClientRect().height).toBe(
  pixels(expected.values['container.height']!),
);
```

Prefer, in order: `DOMRect` geometry → computed CSS properties on the rendered target → (only when nothing observable exists) the generated custom property. If your assertion's left and right sides both originate from tproc, it is not a contract.

## The bridge: getting tproc values into the browser

tproc is Node-only (top-level async DB load). Browser tests reach it through a Vitest Browser command, **not** by importing the DB.

- Node side: `packages/material-x/tests/support/visual-contracts.node.ts` — defines `resolveTokenContract` and the contract registry (`BUTTON_SIZE_CONTRACTS`, …). This is the live source of truth for **which contract IDs exist** — read it; do not maintain a list of IDs anywhere else.
- Browser side: `commands.resolveTokenContract({ contract, state, tokens })` from `vitest/browser`, typed in `tests/support/browser-commands.ts`.

```ts
import { commands } from 'vitest/browser';

const expected = await commands.resolveTokenContract({
  contract: testCase.contract, // e.g. 'button.size.large'
  state: 'default',
  tokens: ['container.height', 'label-text.font-size'],
});
// expected.values['container.height'] -> the tproc value, serializable
```

### Adding a new contract

Register the component's production `ReadonlySignal<TokenPackage>` under a stable ID in the registry. Use the **same signal that generates the component's CSS** (import it from the component's `styles/**/tokens.ts`), so `append`, `adjust`, and inheritance are part of the expected contract. Do not rebuild a package for tests. The registry MUST reject unknown contracts, states, and tokens — the existing `resolveTokenContract` already throws on each.

## effective vs. state

- Read `TokenPackage.effective(path)` — the fully inherited state. This is the default.
- Read `state(path)` only when the unit under test _is_ deduplication or exact CSS emission (it may omit inherited values).

## Fail loudly — never let a missing oracle become a skipped assertion

A missing package, state, or token is a test failure, not a passing no-op. `resolveTokenContract` throws on all three; keep it that way. On the browser side, assert on `values['token']!` (non-null) or throw — never optional-chain a missing oracle into `undefined === undefined`.

## Bindings carry semantics, not values

A component's spec fixtures (`*.spec.fixtures.ts`) describe _how to observe_ a token — the contract ID, state, target selector, and which metric/property. They MUST NOT contain the resolved Material value; that comes from the bridge at runtime. See `button.spec.fixtures.ts` for the current shape (contract + attribute per case).

## Normalization: centralize when shared, inline when local

tproc emits CSS-oriented strings (`px`, `ms`, colors, font lists, `var()` with fallbacks); browser APIs may serialize the same value differently. Convert once, in one tested place:

- If an adapter is used by **one** component, a small local helper (like `pixels()` in the button spec) is fine.
- The moment a second component needs the same conversion, promote it to `tests/support` and unit-test it there. Do not reimplement color/length/font normalization per component.

Adapters to expect as they arrive: CSS color → canonical serialization; font-family list normalization; length → CSS px / numeric DOMRect; border-radius expansion; opacity → number; duration → ms; `full` shape → `rendered block size / 2`; elevation level → shadow; state-layer opacity observed on a pseudo-element.

When an expected value contains a **public CSS variable**, resolve it in a hidden probe under the same fixture theme and compare computed-to-computed. Never compare raw `var()` text.

## Derived values are named formulas, not copied results

A requirement computed from tokens is a named formula over token-backed inputs, referenced by name — e.g. `round radius = rendered container block size / 2` (see the button spec's "derive the round radius" test). Do not copy the per-size result into a fixture.

## Non-token literals need provenance

If no tproc token represents a requirement, a literal is allowed only with `source`, `reviewed` date, and a `reason` it cannot come from tproc. First confirm it isn't already available from an effective package, a shared core package, or a derived formula.

## What a passing contract does and does not prove

It proves the component selected the intended production package and effective state, that runtime state + selectors applied it to the right element, and that the observable rendering agrees. It does **not** prove upstream Material data is correct — that is the job of the tproc node tests and source review. Do not claim conformance from this layer alone.

## Validating or debugging the upstream source

When you suspect the _input_ is wrong — a token resolves to an unexpected value, a token is deprecated, or you need to see what upstream tokens exist — inspect the raw M3 DB with the **use-tokens-db** skill (`db.getValue`, reference trees, deprecation, tag enumeration).

Use it for investigation only. The raw DB is **not** an independent oracle for a contract: tproc reads that same DB, so asserting a rendered value against `db.getValue` is as circular as reading back the generated custom property. Contract expectations come from the bridge (`resolveTokenContract` → `effective`); raw-DB queries help you decide whether a _disagreement_ is an upstream/tproc problem or a runtime/CSS one.

Versions

The database has no other skills named test-visual-contract.

Database snapshot: 13.11.2026 · package version 90356dc41556 (SHA-256 digest of the entire package)

Downloads in the last 30 days: 0 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 100test-component
    Write or migrate tests for an @ydinjs/material-x component — file placement under packages/material-x/tests, the .browser/.spec.browser/.visual.browser/.node suffix and Vitest project routing, rendering/interaction rules (real custom element, real browser input), and the…
  • 100use-tokens-db
    Query Material Design upstream design tokens through @ydinjs/tproc (colors, typography, elevation, shapes, motion) for buttons, FABs, text fields, checkboxes, lists, etc. Use when you need a token's resolved value, its reference tree, its token set, deprecation status, or need…
  • 100contract-test-creator
    Create contract test creator operations. Auto-activating skill for Test Automation. Triggers on: contract test creator, contract test creator Part of the Test Automation skill category. Use when writing or running tests. Trigger with phrases like "contract test creator",…
  • 90midnight-cq:dapp-testing
    This skill should be used when the user asks to test my dapp, write e2e tests, test wallet connection, playwright midnight, test transaction UI, integration test frontend, end-to-end test, browser test, test UI with contract, write Playwright tests for a Midnight dapp, mock…
  • 100generate
    Generate Playwright tests. Use when user says "write tests", "generate tests", "add tests for", "test this component", "e2e test", "create test for", "test this page", or "test this feature".
  • 100generate
    Generate Playwright tests. Use when user says "write tests", "generate tests", "add tests for", "test this component", "e2e test", "create test for", "test this page", or "test this feature".

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.