-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(react): fix BreadcrumbLink type interface to correctly allow for …
…polymorphic anchor components (#1441)
- Loading branch information
Showing
5 changed files
with
61 additions
and
3 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
File renamed without changes.
55 changes: 55 additions & 0 deletions
55
packages/react/src/components/Breadcrumb/BreadcrumbLink.test.tsx
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,55 @@ | ||
import React, { createRef } from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import { BreadcrumbLink } from './'; | ||
import axe from '../../axe'; | ||
|
||
const CustomLinkComponent = ( | ||
props: React.AnchorHTMLAttributes<HTMLAnchorElement> | ||
): JSX.Element => ( | ||
// eslint-disable-next-line jsx-a11y/anchor-has-content | ||
<a data-testid="custom" {...props} /> | ||
); | ||
|
||
test('should render breadcrumb link', () => { | ||
render(<BreadcrumbLink href="#">link</BreadcrumbLink>); | ||
expect(screen.getByRole('link', { name: 'link' })).toBeInTheDocument(); | ||
}); | ||
|
||
test('should support className prop', () => { | ||
render( | ||
<BreadcrumbLink className="banana" href="#"> | ||
link | ||
</BreadcrumbLink> | ||
); | ||
expect(screen.getByRole('link')).toHaveClass( | ||
'Link', | ||
'Breadcrumb__Link', | ||
'banana' | ||
); | ||
}); | ||
|
||
test('should support as prop', () => { | ||
render( | ||
<BreadcrumbLink href="#" as={CustomLinkComponent}> | ||
link | ||
</BreadcrumbLink> | ||
); | ||
expect(screen.getByTestId('custom')).toBeInTheDocument(); | ||
}); | ||
|
||
test('should support ref prop', () => { | ||
const anchorRef = createRef<HTMLAnchorElement>(); | ||
render( | ||
<BreadcrumbLink href="#" ref={anchorRef}> | ||
link | ||
</BreadcrumbLink> | ||
); | ||
expect(anchorRef.current).toBeTruthy(); | ||
expect(anchorRef.current).toEqual(screen.getByRole('link')); | ||
}); | ||
|
||
test('should return no axe violations', async () => { | ||
render(<BreadcrumbLink href="#">link</BreadcrumbLink>); | ||
const results = await axe(screen.getByRole('link', { name: 'link' })); | ||
expect(results).toHaveNoViolations(); | ||
}); |
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