# Testing Shadow DOM Components with Astral ## The Problem When testing web components that use Shadow DOM, traditional selectors can't reach into shadow roots. This is especially challenging when components are nested multiple levels deep, each with their own shadow DOM. ## The Solution: Data Attributes + Pierce Strategy Instead of navigating through shadow DOM boundaries manually, we use **unique data attributes on the actual HTML elements** combined with Astral's **pierce strategy**. ### The Pattern 1. **Add data attributes to the actual HTML elements** (not the custom element wrapper) ```typescript // In ct-input component's render(): // In ct-button component's render():