forked from riccardobertolini/lofi-music
-
Notifications
You must be signed in to change notification settings - Fork 0
/
IconButton.test.tsx
42 lines (37 loc) · 1.22 KB
/
IconButton.test.tsx
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
import React from 'react'
import { render, fireEvent } from '@testing-library/react'
import IconButton from './../IconButton'
// Mocking the useAccessibilityContext hook
jest.mock('../../contexts/AccessibilityContext', () => ({
useAccessibilityContext: jest.fn().mockReturnValue({ tabIndex: 3 }),
}))
describe('IconButton', () => {
it('renders children correctly', () => {
const { getByText } = render(<IconButton>Click Me</IconButton>)
expect(getByText('Click Me')).toBeInTheDocument()
})
it('handles onClick correctly', () => {
const handleClick = jest.fn()
const { getByText } = render(
<IconButton onClick={handleClick}>Click Me</IconButton>,
)
fireEvent.click(getByText('Click Me'))
expect(handleClick).toHaveBeenCalled()
})
it('applies the correct tabIndex', () => {
const { getByText } = render(<IconButton>Click Me</IconButton>)
expect(getByText('Click Me').closest('button')).toHaveAttribute(
'tabindex',
'3',
)
})
it('renders with correct type', () => {
const { getByText } = render(
<IconButton type="submit">Click Me</IconButton>,
)
expect(getByText('Click Me').closest('button')).toHaveAttribute(
'type',
'submit',
)
})
})