Logotipo de Component Testing

Component Testing

Organización
staple-lab
component-testing

Use when writing or reviewing tests for design system components - behavioural tests with Vitest and Testing Library, keyboard and focus tests, axe accessibility assertions, controlled/uncontrolled parity, visual regression, and Storybook play functions. Triggers on "test this component", "a11y test", "visual regression", "storybook test".

Add to TypingMind

Descripción general

Editorstaple-lab
Repositoriodesign-system-skills
Nombre de la habilidadcomponent-testing
Estrellas
7
Forks
0
Archivos incluidos
Solo instrucciones
LicenciaMIT
Enlaces
  • Instrucciones en Markdown

    Un archivo SKILL.md que el modelo carga cuando lo necesita, de modo que solo consume tokens cuando la petición encaja con la habilidad.

  • Funciona con cualquier LLM

    Las habilidades de IA están en Markdown, no en código específico de un proveedor, por lo que funcionan con GPT, Claude, Gemini, Grok o un modelo local.

  • Todo en las instrucciones

    Todo lo que necesita el modelo está en las instrucciones: no hay archivos adicionales que sincronizar.

  • Código abierto

    Publicada por staple-lab en GitHub. Revisa el contenido original antes de instalarla.

Instalación

Instala la habilidad de IA Component Testing en TypingMind para usarla con cualquier LLM, o añádela a otro agente que lea SKILL.md.

1

Instalar en TypingMind

TypingMind instala una habilidad directamente desde su carpeta de GitHub: lee SKILL.md, empaqueta los archivos de recursos y guarda el resultado localmente.

  1. Abre la aplicación y ve a Plugins → Habilidades.
  2. Elige «Instalar desde GitHub».
  3. Pega la URL de la carpeta de la habilidad que se muestra a continuación y confirma.
    https://github.com/staple-lab/design-system-skills/tree/main/plugins/design-system/skills/component-testing
  4. Activa la habilidad en cada chat en el que quieras tenerla disponible.
Plugins → Habilidades → Añadir habilidad → URL de GitHub; después, pega la URL de la carpeta y pulsa Continuar.
2

Instalar en otro agente

Cualquier agente que lea el formato Agent Skills puede usar esta habilidad: copia la carpeta en el directorio de habilidades de ese agente.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/staple-lab/design-system-skills.git /tmp/design-system-skills
mkdir -p .claude/skills
cp -r /tmp/design-system-skills/plugins/design-system/skills/component-testing .claude/skills/component-testing
Reinicia Claude Code después de copiarla para que detecte la nueva habilidad.

Úsala en TypingMind

Activa Component Testing en cualquier chat de TypingMind y el modelo se encargará del resto. Su nombre y descripción se incluyen en el prompt del sistema y, en cuanto una petición encaja con la habilidad, el modelo carga las instrucciones completas por sí solo. No tienes que invocarla manualmente y no consume tokens hasta que se utiliza.

El modelo carga Component Testing automáticamente en cuanto una petición es relevante para esa habilidad.

Funciona con cualquier modelo de IA

Las habilidades de IA son instrucciones en Markdown, no código específico de un proveedor, por lo que Component Testing no está vinculada al modelo para el que se creó. Instálala una sola vez en TypingMind y úsala con GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama o un modelo local que ejecutes tú, todo con tus propias claves API.

  • Se carga solo cuando se necesita

    El prompt del sistema solo incluye el nombre y la descripción. Las instrucciones se cargan con la primera petición que encaja con la habilidad, por lo que una habilidad que no se usa no supone ningún coste.

  • Cambia de modelo durante el chat

    Como la habilidad contiene instrucciones y no código, cambiar de modelo no impide que funcione: el nuevo modelo lee el mismo archivo SKILL.md.

Instrucciones de la habilidad

Este es el contenido de SKILL.md que carga el modelo. Léelo antes de instalar la habilidad: contiene instrucciones que tu modelo seguirá.

Component testing

A design system component is a contract, and the tests are the executable half of it. Consumers depend on behaviour they never read the source for, so the test suite's job is to make that behaviour impossible to change by accident.

Test behaviour, not implementation

tsx
// Bad — asserts the implementation; breaks on every refactor, catches nothing
expect(wrapper.find('.btn-primary').prop('isOpen')).toBe(true);
expect(container.querySelector('div > span:nth-child(2)')).toBeTruthy();

// Good — asserts what a user experiences
await user.click(screen.getByRole('button', { name: 'Open menu' }));
expect(screen.getByRole('menu')).toBeVisible();
expect(screen.getByRole('menuitem', { name: 'Settings' })).toHaveFocus();

Query by role and accessible name, in this priority: getByRole → getByLabelText → getByText → getByTestId (last resort). This is not stylistic. getByRole('button', { name: 'Save' }) fails when the accessible name breaks, which means your functional tests double as accessibility tests for free. A test suite full of getByTestId passes happily while the component is unusable with a screen reader.

The contract suite

Every component gets these. Copy ${CLAUDE_PLUGIN_ROOT}/templates/testing/Button.contract.test.tsx and adapt — the shape should be identical across components so a reviewer can see at a glance what is missing.

  1. Renders every variant × size × state. Cheap, and catches the CVA key typo that silently renders unstyled.
  2. Keyboard map. Every documented key, including the ones people forget: Escape closes and returns focus to the trigger, Tab order is correct, arrows move within a composite widget, Home/End jump, typeahead selects.
  3. Focus management. Focus moves into a dialog on open and back to the trigger on close. This is the single most commonly broken behaviour in hand-rolled components and the most disorienting for keyboard users.
  4. Controlled and uncontrolled parity. Both modes work; onValueChange fires in both. Test them as two runs of the same assertions.
  5. Ref forwarding. The ref lands on a real DOM node.
  6. className merged, ...rest spread. The escape hatches, as tests — otherwise they rot.
  7. Disabled semantics. Not activatable by click or keyboard, and communicated to assistive tech (disabled or aria-disabled, deliberately chosen — aria-disabled keeps the element focusable, which is often better because a focusable disabled control can explain why).
  8. axe clean, in every variant and both themes.
tsx
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { axe } from 'vitest-axe';

it.each(['primary', 'secondary', 'ghost', 'danger'] as const)('%s variant has no a11y violations', async (variant) => {
  const { container } = render(<Button variant={variant}>Save</Button>);
  expect(await axe(container)).toHaveNoViolations();
});

it('returns focus to the trigger when the dialog closes', async () => {
  const user = userEvent.setup();
  render(<Example />);
  const trigger = screen.getByRole('button', { name: 'Open' });
  await user.click(trigger);
  await user.keyboard('{Escape}');
  expect(trigger).toHaveFocus();
});

Always userEvent, never fireEvent. fireEvent.click dispatches one synthetic event; userEvent.click does the pointerdown/mousedown/focus/mouseup/click sequence a real user produces. Components that pass with fireEvent and fail in the browser are almost always failing on that difference.

What axe does and does not catch

Automated a11y testing catches roughly 30–40% of WCAG issues. It is a floor, not a ceiling, and treating a green axe run as "accessible" is the most common mistake in this area.

Caught: missing labels, contrast (when computable), invalid ARIA, duplicate ids, missing landmarks, non-focusable interactive elements.

Not caught, and therefore your job:

  • Focus order being logical rather than merely present
  • Whether an accessible name is useful ("Button 3" passes)
  • Whether an error message is announced when it appears
  • Whether a live region interrupts at the right moment
  • Whether the keyboard path to a feature is reasonable rather than technically possible
  • Whether the component works with an actual screen reader

Write explicit tests for focus order, announcements and keyboard paths. And at least once per release, drive the component with VoiceOver or NVDA — nothing substitutes for hearing it.

Storybook

Storybook 10's Vitest addon replaced the old @storybook/test-runner. Stories become test cases via play functions, and the a11y addon runs axe in the same pass — one artifact serving docs, manual review and automation.

tsx
export const OpensOnClick: Story = {
  play: async ({ canvasElement, step }) => {
    const canvas = within(canvasElement);
    await step('opens the menu', async () => {
      await userEvent.click(canvas.getByRole('button', { name: 'Options' }));
      await expect(canvas.getByRole('menu')).toBeVisible();
    });
  },
};

The division of labour that works: stories for states worth looking at (they are the docs, and they feed visual regression), unit tests for logic and edge cases (faster, and better failure messages).

Visual regression

Behaviour tests do not catch a broken border radius or a token that resolved to the wrong colour. VRT does, and for a design system it earns its keep more than in a product app because one component change touches every screen.

  • Playwright screenshots — free, deterministic, you host the baselines.
  • Chromatic — hosted, handles review workflow and cross-browser, costs money.

Snapshot every component in: each variant, both themes, and at 200% zoom. Disable animations and freeze anything time-based, or you will spend your life triaging flakes:

ts
await page.emulateMedia({ reducedMotion: 'reduce' });

Keep a strict diff threshold. A loose one means real regressions slip through, which is worse than not having VRT at all — it manufactures false confidence.

Token and theme tests

Cheap, and they catch the failures that are hardest to spot by eye:

ts
it('every semantic token is defined in every theme', () => {
  const { themes } = tokens;
  const paths = Object.keys(themes.light);
  for (const [name, theme] of Object.entries(themes)) {
    expect(Object.keys(theme).sort()).toEqual(paths.sort());   // a hole in a theme is a silent bug
  }
});

it('components reference no primitive tokens directly', () => {
  // tier violations kill theming — the lint rule catches source, this catches the built output
  const css = readFileSync('dist/styles.css', 'utf8');
  expect(css).not.toMatch(/var\(--ds-color-(neutral|accent|success|warning|danger)-\d+\)/);
});

The contrast gate already runs in the token build. Do not duplicate it here; make sure it runs in CI.

What not to test

  • Third-party primitive internals — Radix tests Radix. Test your wrapper's contract.
  • Exact class names or CSS output. That is VRT's job, and asserting on classes is what makes refactors painful.
  • Snapshot tests of rendered markup. They fail on every change and get rubber-stamped with -u, at which point they are pure cost. Targeted assertions or a real VRT tool.

CI gates

typecheck → unit + a11y → token build (contrast gate) → lint → VRT → build → publint/attw

Fail the build on: a11y violations, contrast failures, type errors, DS lint errors. Warn on: coverage dip, bundle-size growth beyond a threshold.

Coverage floor around 80% for a design system — higher than a typical app, because consumers cannot see inside and a regression ships everywhere at once. Do not chase 100%: the last 15% is usually error branches that would need contrived setups, and the effort is better spent on a real screen-reader pass.

Preguntas frecuentes

¿Qué hace la habilidad de IA Component Testing?

Use when writing or reviewing tests for design system components - behavioural tests with Vitest and Testing Library, keyboard and focus tests, axe accessibility assertions, controlled/uncontrolled parity, visual regression, and Storybook play functions. Triggers on "test this component", "a11y test", "visual regression", "storybook test".

¿Por qué usar Component Testing en TypingMind?

Porque la instalas una vez y la usas con cualquier modelo. Component Testing está escrita en Markdown, no en código específico de un proveedor, por lo que la misma habilidad funciona con GPT-5, Claude, Gemini, Grok o un modelo local, y puedes cambiar de modelo en mitad del chat sin que deje de funcionar. TypingMind utiliza tus propias claves API, de modo que pagas directamente a los proveedores en lugar de pagar una suscripción por puesto, y tus habilidades y chats permanecen en tu propio almacenamiento.

¿Cómo instalo Component Testing en TypingMind?

Abre Plugins → Habilidades → Instalar desde GitHub en TypingMind y pega https://github.com/staple-lab/design-system-skills/tree/main/plugins/design-system/skills/component-testing. TypingMind lee el archivo SKILL.md de esa carpeta e instala su contenido como una habilidad que puedes activar en cada chat.

¿Qué modelos de IA pueden usar Component Testing?

Cualquier modelo que conectes en TypingMind. Las habilidades de IA son instrucciones en Markdown, no código específico de un proveedor, por lo que GPT, Claude, Gemini, Grok y los modelos locales pueden cargar esta habilidad cuando una solicitud se corresponda con ella.

¿Con cuántos modelos de IA puedo usar Component Testing?

Con tantos como quieras. Siempre que un modelo admita habilidades, puedes usar Component Testing con él: GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama y muchos más, todos en TypingMind con tus propias claves API.

¿Es gratuita la habilidad de IA Component Testing?

Sí. staple-lab la ha publicado en GitHub bajo la licencia MIT. Solo pagas a tu proveedor de IA por los tokens que utilizas.

¿Qué son las habilidades de IA?

Una habilidad de IA es un conjunto de instrucciones reutilizables que enseña a un modelo de IA a realizar una tarea concreta. Sigue el formato abierto Agent Skills: un archivo SKILL.md con un nombre y una descripción, además de los scripts, plantillas o archivos de referencia que pueda necesitar el modelo. El modelo solo lee las instrucciones cuando tu solicitud se corresponde con la habilidad, por lo que una habilidad instalada no supone ningún coste hasta que se utiliza.

¿En qué se diferencian las habilidades de IA de los plugins o los servidores MCP?

Un plugin o un servidor MCP proporciona al modelo nuevas herramientas que puede invocar: código que se ejecuta en algún lugar y devuelve un resultado. En cambio, una habilidad de IA aporta conocimientos y procedimientos al modelo: cómo abordar una tarea, qué pasos seguir y qué se considera un buen resultado. Las habilidades son instrucciones en Markdown, por lo que no necesitan servidor, clave API ni entorno de ejecución, y funcionan con cualquier modelo.

Ver el directorio

Crea ya tu propio espacio de trabajo con IA

Suscríbete a nuestro boletín para recibir avisos sobre nuevas funciones y próximos sorteos 👇