Skip to content

Commit 8dd1ce7

Browse files
committed
Improve tests on Bar and Button
- Improve Bar tests with blockSizes from commom instead of static values - Test disabled Button callback function
1 parent 32409fc commit 8dd1ce7

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/components/Bar/Bar.spec.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react'
22
import { render } from '@testing-library/react'
3+
import { blockSizes } from '../common/system'
34

45
import Bar from './Bar'
56

@@ -15,11 +16,11 @@ describe('<Bar />', () => {
1516
const { container, rerender } = render(<Bar size='sm' />)
1617
const barEl = container.firstChild
1718

18-
expect(barEl).toHaveStyleRule('height', '27px')
19+
expect(barEl).toHaveStyleRule('height', blockSizes.sm)
1920

2021
rerender(<Bar size='lg' />)
2122

22-
expect(barEl).toHaveStyleRule('height', '43px')
23+
expect(barEl).toHaveStyleRule('height', blockSizes.lg)
2324
})
2425

2526
it('should handle custom style', () => {

src/components/Button/Button.spec.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,14 @@ describe('<Button />', () => {
7979

8080
expect(button.innerHTML).toBe('click me')
8181
})
82+
83+
it('should not fire click when disabled', () => {
84+
const onButtonClick = jest.fn()
85+
const { getByRole } = render(<Button {...defaultProps} disabled />)
86+
const button = getByRole('button')
87+
88+
fireEvent.click(button)
89+
90+
expect(onButtonClick).not.toHaveBeenCalled()
91+
})
8292
})

0 commit comments

Comments
 (0)