-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add test for alert component (#109)
- Loading branch information
1 parent
9ff104b
commit f03d765
Showing
2 changed files
with
42 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import React from 'react' | ||
import { render, screen } from '../../utils/testUtils' | ||
|
||
import Alert from '.' | ||
|
||
describe('<Alert />', () => { | ||
it('should render alert with the given header', () => { | ||
const headerText = 'Header' | ||
render( | ||
<Alert header={headerText}> | ||
<div>This is an alert</div> | ||
</Alert> | ||
) | ||
|
||
expect(screen.getByText(headerText)).toBeInTheDocument() | ||
}) | ||
|
||
it('should render alert with the given children', () => { | ||
const childText = 'This is an alert' | ||
render( | ||
<Alert> | ||
<div>{childText}</div> | ||
</Alert> | ||
) | ||
|
||
expect(screen.getByText(childText)).toBeInTheDocument() | ||
}) | ||
|
||
it('should call onClose function when close is clicked', () => { | ||
const onCloseMockFn = jest.fn() | ||
render( | ||
<Alert closable onClose={onCloseMockFn}> | ||
<div>This is an alert</div> | ||
</Alert> | ||
) | ||
|
||
const closeIcon = screen.getByText('X') | ||
closeIcon!.click() | ||
|
||
expect(onCloseMockFn).toBeCalled() | ||
}) | ||
}) |
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