Skip to content

Commit

Permalink
test: add test for alert component (#109)
Browse files Browse the repository at this point in the history
  • Loading branch information
KiruthikaJeyashankar committed Oct 15, 2023
1 parent 9ff104b commit f03d765
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
42 changes: 42 additions & 0 deletions src/packages/Alert/test.tsx
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()
})
})
1 change: 0 additions & 1 deletion src/packages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,3 @@ export { default as Skeleton } from './Skeleton'
export { default as Switch } from './Switch'
export { default as Table } from './Table'
export { default as Pagination } from './Pagination'

0 comments on commit f03d765

Please sign in to comment.