diff options
| author | Norton <2773923088@qq。> | 2026-04-06 14:32:33 +0800 |
|---|---|---|
| committer | Norton <2773923088@qq。> | 2026-04-06 14:32:33 +0800 |
| commit | 18fc18761dbefc2ab2fbaf93e1fe433eb0b47b37 (patch) | |
| tree | 8c5c83f9e45387123e79f3431d1eb1ab66a020ea /src/components/ui/card.test.tsx | |
| parent | f247a8c4a863ec430f4a705b5c493d652c8429bd (diff) | |
A small portion of newly added unit testing code
Diffstat (limited to 'src/components/ui/card.test.tsx')
| -rw-r--r-- | src/components/ui/card.test.tsx | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/components/ui/card.test.tsx b/src/components/ui/card.test.tsx index aba3d00..0c29c5d 100644 --- a/src/components/ui/card.test.tsx +++ b/src/components/ui/card.test.tsx @@ -36,5 +36,29 @@ describe('Card', () => { expect(screen.getByText('Content')).toHaveAttribute('data-slot', 'card-content'); expect(screen.getByText('Footer')).toHaveAttribute('data-slot', 'card-footer'); }); + + test('appends custom class names correctly', () => { + render( + <Card className="my-custom-card-class"> + <CardContent className="my-custom-content-class">Content</CardContent> + </Card> + ); + + const cardElement = screen.getByText('Content').parentElement; // 或者直接给 Card 加个 data-testid + expect(cardElement).toHaveClass('my-custom-card-class'); + expect(screen.getByText('Content')).toHaveClass('my-custom-content-class'); + }); + + test('passes standard HTML attributes to the DOM node', () => { + render( + <Card id="test-card" aria-label="Test Card"> + <CardContent data-testid="content-id">Content</CardContent> + </Card> + ); + + const cardElement = screen.getByLabelText('Test Card'); + expect(cardElement).toHaveAttribute('id', 'test-card'); + expect(screen.getByTestId('content-id')).toBeInTheDocument(); + }); }); |
