Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: class to function component
- Loading branch information
Showing
2 changed files
with
64 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,43 @@ | ||
import TestUtil from '../../Util/TestUtil'; | ||
import SimpleButton, {SimpleButtonProps} from './SimpleButton'; | ||
import { fireEvent,render, screen } from '@testing-library/react'; | ||
import React from 'react'; | ||
|
||
import SimpleButton from './SimpleButton'; | ||
|
||
describe('<SimpleButton />', () => { | ||
|
||
it('is defined', () => { | ||
expect(SimpleButton).not.toBeUndefined(); | ||
expect(SimpleButton).toBeDefined(); | ||
}); | ||
|
||
it('can be rendered', () => { | ||
const wrapper = TestUtil.mountComponent(SimpleButton); | ||
expect(wrapper).not.toBeUndefined(); | ||
it('can rendered', () => { | ||
render(<SimpleButton />); | ||
expect(screen.getByRole('button')).toBeVisible(); | ||
}); | ||
|
||
it('allows to set some props', () => { | ||
const wrapper = TestUtil.mountComponent(SimpleButton); | ||
|
||
wrapper.setProps({ | ||
type: 'secondary', | ||
shape: 'circle', | ||
size: 'small', | ||
disabled: true | ||
}); | ||
|
||
const props = wrapper.props() as SimpleButtonProps; | ||
expect(props.type).toBe('secondary'); | ||
expect(props.shape).toBe('circle'); | ||
expect(props.size).toBe('small'); | ||
expect(props.disabled).toBe(true); | ||
|
||
expect(wrapper.find('button.ant-btn-secondary').length).toBe(1); | ||
expect(wrapper.find('button.ant-btn-circle').length).toBe(1); | ||
expect(wrapper.find('button.ant-btn-sm').length).toBe(1); | ||
expect(wrapper.find('button').length).toBe(1); | ||
render( | ||
<SimpleButton | ||
type="default" | ||
shape="circle" | ||
size="small" | ||
disabled={true} | ||
/> | ||
); | ||
|
||
const button = screen.getByRole('button'); | ||
expect(button).toHaveClass('ant-btn-default'); | ||
expect(button).toHaveClass('ant-btn-circle'); | ||
expect(button).toHaveClass('ant-btn-sm'); | ||
expect(button).toBeDisabled(); | ||
}); | ||
|
||
it('calls a given click callback method onClick', () => { | ||
const onClick = jest.fn(); | ||
const wrapper = TestUtil.mountComponent(SimpleButton, {onClick}); | ||
render(<SimpleButton onClick={onClick} />); | ||
|
||
wrapper.find('button').simulate('click'); | ||
const button = screen.getByRole('button'); | ||
fireEvent.click(button); | ||
|
||
expect(onClick).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters