-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4699 from cloud-gov/chore-test-shared-buttonLink-…
…4672 chore: test @shared/ButtonLink.jsx #4672
- Loading branch information
Showing
2 changed files
with
38 additions
and
5 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
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import React from 'react'; | ||
import { render, screen, fireEvent } from '@testing-library/react'; | ||
import '@testing-library/jest-dom'; | ||
|
||
import ButtonLink from './ButtonLink'; | ||
const clickHandler = jest.fn(); | ||
|
||
describe('<ButtonLink />', () => { | ||
it('renders children as expected', () => { | ||
render(<ButtonLink clickHandler={clickHandler}>child text</ButtonLink>); | ||
const buttonElement = screen.getByRole('button'); | ||
expect(buttonElement).toHaveTextContent('child text'); | ||
}); | ||
|
||
it('calls the clickHandler when clicked', () => { | ||
render(<ButtonLink clickHandler={clickHandler}>Click Me</ButtonLink>); | ||
const buttonElement = screen.getByText('Click Me'); | ||
fireEvent.click(buttonElement); | ||
expect(clickHandler).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it('applies the className as expected', () => { | ||
render( | ||
<ButtonLink clickHandler={clickHandler} className="custom-class"> | ||
Class Button | ||
</ButtonLink>, | ||
); | ||
const buttonElement = screen.getByText('Class Button'); | ||
expect(buttonElement).toHaveClass('usa-button custom-class'); | ||
}); | ||
|
||
it('defaults to usa-button--outline class if no className is provided', () => { | ||
render(<ButtonLink clickHandler={clickHandler}>No Class</ButtonLink>); | ||
const buttonElement = screen.getByText('No Class'); | ||
expect(buttonElement).toHaveClass('usa-button--outline'); | ||
}); | ||
}); |