Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(SecondaryButton): Enzyme->RTL - refactor out the render in setup #12805

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,40 @@ import { screen, render } from '@testing-library/react';
import '@testing-library/jest-dom';
import SecondaryButton from '../SecondaryButton';

const prefix = 'cds';

describe('SecondaryButton', () => {
describe('Renders as expected', () => {
const renderSecondaryButton = (props) => {
it('Renders children as expected', () => {
render(
<SecondaryButton {...props} className="extra-class" size="sm">
<SecondaryButton>
<div className="child">Test</div>
<div className="child">Test</div>
</SecondaryButton>
);
};

it('Renders children as expected', () => {
renderSecondaryButton();
expect(screen.getAllByText('Test').length).toBe(2);
});

it('Has the expected kind set to "secondary"', () => {
renderSecondaryButton();
expect(screen.getByRole('button')).toHaveClass('cds--btn--secondary');
render(<SecondaryButton />);
expect(screen.getByRole('button')).toHaveClass(
`${prefix}--btn--secondary`
);
});

it('Should add extra classes that are passed via className', () => {
renderSecondaryButton();
render(<SecondaryButton className="extra-class" />);
expect(screen.getByRole('button')).toHaveClass('extra-class');
});

describe('Renders icon buttons', () => {
it('should have the appropriate icon', () => {
renderSecondaryButton({
iconDescription: 'Search',
renderIcon: Search,
});
expect(screen.queryByLabelText('Search')).toHaveClass('cds--btn__icon');
render(
<SecondaryButton iconDescription={'Search'} renderIcon={Search} />
);
expect(screen.queryByLabelText('Search')).toHaveClass(
`${prefix}--btn__icon`
);
});
});
});
Expand Down