TWD + shadcn/ui Testing Guide
December 22, 2025 ยท View on GitHub
A comprehensive interactive guide demonstrating how to test shadcn/ui components using TWD (Testing While Developing).
๐ฏ What is This?
This repository showcases testing patterns for 22+ shadcn/ui components. Each component page displays:
- Live Component Preview โ Interactive demonstration
- Component Code โ Reusable implementation example
- TWD Test Code โ Complete test patterns with recommended selectors
Perfect for developers learning how to test shadcn/ui components effectively.
๐ฆ Features
- 21 Fully Documented Components with TWD tests
- 2 WIP Placeholder Pages (Range Calendar, Data Table)
๐ Getting Started
Prerequisites
- Node.js 18+
- npm or yarn
Installation
npm install
Development
npm run dev
Opens at http://localhost:5173 with TWD test sidebar enabled in dev mode.
Build
npm run build
Optimized production build ready for GitHub Pages or any static host.
๐ Component Coverage
โ Fully Implemented (With TWD Tests)
- Accordion
- Alert Dialog
- Breadcrumb
- Button
- Calendar
- Checkbox
- Collapsible
- Command
- Context Menu
- Dialog
- Drawer
- Dropdown Menu
- Pagination
- Popover
- Radio Group
- Select
- Slider
- Sonner
- Switch
- Table (Basic)
- Tabs
- Tooltip
๐ง Work in Progress (WIP)
- Range Calendar
- Data Table (TanStack)
๐งช Testing Patterns
Key Testing Concepts
screenDom โ Standard DOM queries
await screenDom.findByRole('button', { name: 'Click me' });
screenDomGlobal โ Portal-rendered elements (dialogs, popovers, tooltips)
await screenDomGlobal.findByText('Tooltip content');
Assertions
twd.should(element, 'be.visible');
expect(element).eql(null); // For non-existence
Selector Best Practices
- Tables: Use
role:'table',columnheader, text content for rows - Portals: Use
screenDomGlobalfor dialogs, drawers, popovers, tooltips - Forms: Use
findByLabelText(),findByRole()for inputs - Navigation: Use link text and button names
๐ Resources
๐ License
MIT
Happy TWD Testing! ๐