ui-data-testid

Standardize and preserve data-testid attributes across React/TSX UI components.

5.0k|548|Updated May 14, 2025
One-click install
npx skills add https://github.com/dtyq/magic --skill ui-data-testid
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: ui-data-testid
Source: https://github.com/dtyq/magic/tree/main/frontend/magic-web/.agents/skills/ui-data-testid
Command: npx skills add https://github.com/dtyq/magic --skill ui-data-testid

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Data-testid attributes are often broken or dropped during UI refactors, translations, or design updates, causing fragile tests and flaky automation.

Core Features & Use Cases

  • Add and enforce stable data-testid attributes on root containers and primary interactive nodes (buttons, inputs, menus, modals) across UI components.
  • Forward and preserve data-testid values through config-driven renderers and wrappers to maintain testability in refactors.
  • Support in-code naming conventions (lowercase, kebab-case, semantic suffixes) to ensure consistent test selectors across projects.

Quick Start

Add or preserve stable data-testid attributes for a new or refactored UI component to enable reliable tests.

Frequently Asked Questions about ui-data-testid

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
Why do my data-testid attributes break during UI refactors and translations?

Data-testid attributes break during refactors because dynamic values or text-based selectors change when components update. Standardizing stable, text-agnostic ids on root containers and interactive nodes prevents this test brittleness across React and TSX views.

How do I add stable data-testid attributes to React components for test automation?

Add stable data-testid attributes by applying lowercase, kebab-case naming conventions with semantic suffixes to primary interactive nodes like buttons and inputs. This forwards ids through config-driven renderers to support reliable unit and end-to-end tests.

Does this approach support config-driven renderers in shadcn and antd-style components?

Config-driven renderers in shadcn and antd-style components are fully supported. The process forwards and preserves data-testid values through wrappers and dropdown menu configs to maintain testability during design updates.

What is the best way to preserve test selectors when updating dropdown menus and modals?

The best way to preserve test selectors is enforcing stable, text-agnostic data-testid ids on interactive flows. Applying semantic suffixes to menus and modals minimizes automation flakiness caused by translation or design changes.

Can I use dynamic values for data-testid in interactive flows without causing flaky tests?

Dynamic values for data-testid should be avoided entirely. Enforcing static, text-agnostic ids across interactive flows prevents test flakiness and ensures automation stability during UI component refactors.

When do I need to standardize data-testid attributes across my frontend components?

Standardize data-testid attributes when establishing test automation for React or TSX views. Consistent naming conventions across root containers and interactive nodes ensure reliable unit and end-to-end test execution.