Skip to content

Commit 5d8d31a

Browse files
Add tests for summary list action as custom element
1 parent dee21bf commit 5d8d31a

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/components/content-presentation/summary-list/__tests__/SummaryList.test.tsx

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { render } from '@testing-library/react';
2-
import { createRef } from 'react';
2+
import { createRef, type ComponentProps } from 'react';
33

44
import { SummaryList } from '..';
55

@@ -96,6 +96,26 @@ describe('SummaryList', () => {
9696
expect(container).toMatchSnapshot();
9797
});
9898

99+
it('renders as custom element', () => {
100+
function CustomLink({ children, href, ...rest }: ComponentProps<'a'>) {
101+
return (
102+
<a href={href} {...rest} data-custom-link="true">
103+
{children}
104+
</a>
105+
);
106+
}
107+
108+
const { container } = render(
109+
<SummaryList.Action href="#" visuallyHiddenText="example key" asElement={CustomLink}>
110+
Edit
111+
</SummaryList.Action>,
112+
);
113+
114+
const rowActionEl = container.querySelector('a');
115+
116+
expect(rowActionEl?.dataset).toHaveProperty('customLink', 'true');
117+
});
118+
99119
it('forwards refs', () => {
100120
const ref = createRef<HTMLAnchorElement>();
101121

0 commit comments

Comments
 (0)