Skip to content

Commit 7c00042

Browse files
Add unit test
1 parent ab76ba5 commit 7c00042

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

packages/web/src/components/gcds-nav-link/gcds-nav-link.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
h,
1111
} from '@stencil/core';
1212
import { assignLanguage, observerConfig, emitEvent } from '../../utils/utils';
13-
import i18n from '../gcds-link/i18n/i18n'
13+
import gcdsLinkI18n from '../gcds-link/i18n/i18n'
1414

1515
/**
1616
* Navigation link within a navigation group or menu, allowing users to navigate to different sections of a website or application.
@@ -113,7 +113,7 @@ export class GcdsNavLink {
113113
const isExternal = external;
114114

115115
if (isExternal) {
116-
return <gcds-icon name="external" label={i18n[lang].external} />;
116+
return <gcds-icon name="external" label={gcdsLinkI18n[lang].external} />;
117117
}
118118

119119
return null;

packages/web/src/components/gcds-nav-link/test/gcds-nav-link.spec.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { newSpecPage } from '@stencil/core/testing';
22
import { GcdsNavLink } from '../gcds-nav-link';
33

4+
import gcdsLinkI18n from '../../gcds-link/i18n/i18n'
5+
46
describe('gcds-nav-link', () => {
57
it('renders', async () => {
68
const page = await newSpecPage({
@@ -34,4 +36,23 @@ describe('gcds-nav-link', () => {
3436
</gcds-nav-link>
3537
`);
3638
});
39+
it('renders external', async () => {
40+
const page = await newSpecPage({
41+
components: [GcdsNavLink],
42+
html: `<gcds-nav-link href="#link" external>Nav Link</gcds-nav-link>`,
43+
});
44+
expect(page.root).toEqualHtml(`
45+
<gcds-nav-link external="" href="#link" role="listitem">
46+
<mock:shadow-root>
47+
<a rel="noopener noreferrer" target="_blank" class="gcds-nav-link gcds-nav-link--sidenav" href="#link" tabindex="0">
48+
<slot></slot>
49+
<span class="text-icon-group">
50+
<gcds-icon name="external" label="${gcdsLinkI18n.en.external}" />
51+
</span>
52+
</a>
53+
</mock:shadow-root>
54+
Nav Link
55+
</gcds-nav-link>
56+
`);
57+
});
3758
});

0 commit comments

Comments
 (0)