-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: addresses new to test for props in NavLink componenet
- Loading branch information
1 parent
fa1f00b
commit 61a2961
Showing
1 changed file
with
30 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { render, screen, fireEvent } from '@testing-library/react'; | ||
import NavLink from './NavLink'; | ||
|
||
describe('NavLink componenet', () => { | ||
it('renders link with href and testId', () => { | ||
render( | ||
<NavLink href="test/url" testId="test-link"> | ||
Test Link | ||
</NavLink>, | ||
); | ||
|
||
const link = screen.getByTestId('test-link'); | ||
expect(link).toBeInTheDocument(); | ||
expect(link).toHaveAttribute('href', 'test/url'); | ||
expect(link).toHaveTextContent('Test Link'); | ||
}); | ||
|
||
it('calls onClose when link is clicked', () => { | ||
const handleClose = jest.fn(); | ||
render( | ||
<NavLink href="/test-url" testId="test-link" onClose={handleClose}> | ||
Test Link | ||
</NavLink>, | ||
); | ||
|
||
const linkNav = screen.getByTestId('test-link'); | ||
fireEvent.click(linkNav); | ||
expect(handleClose).toHaveBeenCalledTimes(1); | ||
}); | ||
}); |