feat: store and component mocks setup (#237)

* feat: store and component mocks setup

* feat: more examples
This commit is contained in:
Yusuf Seyrek
2023-05-30 11:16:13 +02:00
committed by GitHub
parent 0c959d5097
commit e651e9c797
9 changed files with 109 additions and 18 deletions
+27 -3
View File
@@ -1,4 +1,4 @@
import { render } from '@testing-library/react'
import { cleanup, render } from '@testing-library/react'
import Button from 'components/Button'
import {
@@ -7,10 +7,18 @@ import {
buttonVariantClasses,
focusClasses,
} from 'components/Button/constants'
import { parseMockComponent } from 'utils/testing'
jest.mock('components/CircularProgress', () => {
const { createMockComponent } = require('utils/testing')
return {
CircularProgress: (props: any) => createMockComponent('circular-progress-component', props),
}
})
describe('<Button />', () => {
afterAll(() => {
jest.resetAllMocks()
jest.clearAllMocks()
})
it('should render', () => {
@@ -66,8 +74,24 @@ describe('<Button />', () => {
it('should show progress indicator when `showProgressIndicator=true`', () => {
const { getByTestId } = render(<Button showProgressIndicator={true} />)
const circularProgressComponent = getByTestId('circular-progress-component')
expect(getByTestId('circular-progress-component')).toBeInTheDocument()
expect(circularProgressComponent).toBeInTheDocument()
})
it('should set correct values for progress indicator size', () => {
const sizeValues = { small: 10, medium: 12, large: 18 }
Object.entries(sizeValues).forEach(([size, value]) => {
const { getByTestId } = render(
<Button showProgressIndicator={true} size={size as keyof typeof buttonSizeClasses} />,
)
const circularProgressComponent = getByTestId('circular-progress-component')
const sizeProp = parseMockComponent(circularProgressComponent).size
expect(sizeProp).toBe(value)
cleanup()
})
})
it('should handle `size` prop correctly', () => {