generated from nimblehq/git-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#7] Add tests for Button and cleanup
- Loading branch information
1 parent
8b2c6d4
commit ebd3198
Showing
5 changed files
with
48 additions
and
19 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,33 @@ | ||
import { render, screen } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
|
||
import Button from '.'; | ||
|
||
const handleButtonClick = jest.fn(); | ||
|
||
describe('Button', () => { | ||
test('renders a button on the page', () => { | ||
render(<Button text="Click me" type="button" onButtonClick={handleButtonClick} />); | ||
|
||
const buttonComponent = screen.getByRole('button', { name: 'Click me' }); | ||
|
||
expect(buttonComponent).toBeInTheDocument(); | ||
expect(buttonComponent).toHaveAttribute('type', 'button'); | ||
}); | ||
|
||
it('renders a button with the given class', () => { | ||
render(<Button text="Click me" type="button" className="primary" onButtonClick={handleButtonClick} />); | ||
|
||
const buttonComponent = screen.getByRole('button', { name: 'Click me' }); | ||
|
||
expect(buttonComponent).toHaveClass('primary'); | ||
}); | ||
|
||
test('when clicked, calls onButtonClick handler', async () => { | ||
render(<Button text="Click me" type="button" onButtonClick={handleButtonClick} />); | ||
|
||
await userEvent.click(screen.getByRole('button', { name: 'Click me' })); | ||
|
||
expect(handleButtonClick).toBeCalledTimes(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
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