Skip to content

Commit

Permalink
fix: addresses new to test for props in NavLink componenet
Browse files Browse the repository at this point in the history
  • Loading branch information
HoldUpFjord committed Nov 20, 2024
1 parent fa1f00b commit 61a2961
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions components/NavLink/NavLink.test.tsx
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);
});
});

0 comments on commit 61a2961

Please sign in to comment.