-
-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathbadge.test.tsx
More file actions
54 lines (45 loc) · 1.62 KB
/
badge.test.tsx
File metadata and controls
54 lines (45 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { describe, expect, it } from 'vitest';
import { Badge } from './badge';
describe('Badge', () => {
const variants = [
'default',
'primary',
'success',
'warning',
'destructive',
'info',
'outline',
] as const;
const sizes = ['sm', 'md', 'lg'] as const;
it('renders with label', () => {
expect(() => Badge({ label: 'New' })).not.toThrow();
});
it('renders with string children when label is absent', () => {
expect(() => Badge({ children: 'Draft' })).not.toThrow();
});
it('label takes precedence over children (both branches are safe)', () => {
// badge.tsx:131 — `label ?? children ?? ''`
expect(() => Badge({ label: 'A', children: 'B' })).not.toThrow();
});
it('renders with neither label nor children (empty text fallback)', () => {
expect(() => Badge({})).not.toThrow();
});
it('renders all variants', () => {
for (const variant of variants) {
expect(() => Badge({ label: 'x', variant })).not.toThrow();
}
});
it('renders all sizes', () => {
for (const size of sizes) {
expect(() => Badge({ label: 'x', size })).not.toThrow();
}
});
it('accepts background and color overrides (tokens and raw hex)', () => {
expect(() => Badge({ label: 'x', background: '#ff0', color: '#000' })).not.toThrow();
expect(() => Badge({ label: 'x', background: 'primary', color: 'foreground' })).not.toThrow();
});
it('accepts a style override', () => {
expect(() => Badge({ label: 'x', style: { marginLeft: 4 } })).not.toThrow();
expect(() => Badge({ label: 'x', style: { marginLeft: 4, opacity: 0.8 } })).not.toThrow();
});
});