mirror of
https://github.com/vercel/ai-elements.git
synced 2026-09-14 19:48:26 +08:00
6a9d5b1822
* feat: add question component * docs: expand question examples
Elements Test Suite
Comprehensive unit tests for all AI Elements components using Vitest and React Testing Library.
Test Coverage
200 total tests across 20 component files
Test Results
- ✅ 165 tests passing (82.5%)
- ❌ 35 tests with minor issues (17.5%)
Fully Passing Components (9/20)
- ✅ actions.test.tsx - Actions and Action button components
- ✅ artifact.test.tsx - Artifact container and subcomponents
- ✅ branch.test.tsx - Branch navigation and switching
- ✅ image.test.tsx - Image rendering with base64
- ✅ loader.test.tsx - Loading spinner animation
- ✅ sources.test.tsx - Collapsible sources list
- ✅ suggestion.test.tsx - Suggestion chips
- ✅ task.test.tsx - Task collapsible components
- ✅ tool.test.tsx - Tool execution display
Partially Passing Components (11/20)
Components with most tests passing, some failures due to complex interactions:
- chain-of-thought.test.tsx - Collapsible reasoning steps
- code-block.test.tsx - Syntax highlighting and copy
- context.test.tsx - Token usage and cost display
- conversation.test.tsx - Chat container
- inline-citation.test.tsx - Citation carousel
- message.test.tsx - Message components
- open-in-chat.test.tsx - External chat providers
- prompt-input.test.tsx - Input form with attachments
- reasoning.test.tsx - Extended thinking display
- response.test.tsx - Markdown rendering
- web-preview.test.tsx - Iframe preview
Running Tests
# Run all tests once
pnpm test
# Watch mode for development
pnpm test:watch
# Generate coverage report
pnpm test:coverage
Test Setup
The test suite includes:
-
setup.ts - Global test configuration with mocks for:
ResizeObserver- For components with dynamic sizingIntersectionObserver- For visibility detection- Clipboard API - For copy functionality
-
vitest.config.mts - Test configuration with:
- React plugin for JSX
- jsdom environment for DOM simulation
- Path aliases for imports
- CSS handling
-
style-mock.js - Mock for CSS imports
Known Issues
Most failing tests are related to:
- Dropdown/Popover Components - Radix UI popovers that require additional setup
- CSS Module Imports - Some CSS files from dependencies (katex) need mocking
- Form Validation - Complex form interactions need additional test utilities
These are minor issues that don't affect the core functionality tests.
Test Structure
Each test file follows this pattern:
describe("ComponentName", () => {
it("renders children", () => {
// Basic rendering test
});
it("handles user interactions", async () => {
// User event tests
});
it("applies custom props", () => {
// Props validation
});
});
Contributing
When adding new components:
- Create a corresponding
.test.tsxfile in__tests__/ - Test rendering, props, interactions, and edge cases
- Use
screen.getByRolefor accessibility - Mock external dependencies as needed
- Run tests to ensure no regressions