Skip to content

Commit 8eb5c3d

Browse files
committed
test: add unit test
1 parent 2bf0713 commit 8eb5c3d

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { ChannelBtnFilledIcon } from '@channel.io/bezier-icons'
2+
import { render, screen } from '@testing-library/react'
3+
4+
import { Icon } from './Icon'
5+
6+
describe('Icon', () => {
7+
const renderIcon = (props = {}) =>
8+
render(
9+
<Icon
10+
source={ChannelBtnFilledIcon}
11+
{...props}
12+
/>
13+
)
14+
15+
it('should render', () => {
16+
renderIcon()
17+
expect(screen.getByRole('img', { hidden: true })).toBeInTheDocument()
18+
})
19+
20+
describe('Accessibility', () => {
21+
it('should be decorative by default', () => {
22+
renderIcon()
23+
expect(screen.getByRole('img', { hidden: true })).toHaveAttribute(
24+
'aria-hidden',
25+
'true'
26+
)
27+
})
28+
29+
it('should be accessible with aria-label', () => {
30+
renderIcon({ 'aria-label': 'Channel Button' })
31+
expect(screen.getByRole('img')).toHaveAttribute(
32+
'aria-label',
33+
'Channel Button'
34+
)
35+
expect(screen.getByRole('img')).toBeInTheDocument()
36+
})
37+
38+
it('should respect explicit aria-hidden', () => {
39+
renderIcon({ 'aria-hidden': false })
40+
expect(screen.getByRole('img')).toBeInTheDocument()
41+
})
42+
})
43+
})

0 commit comments

Comments
 (0)