Skip to content

Commit aafae87

Browse files
author
Said Shah
committed
Updated and refactored tests for Link Card
1 parent 4389139 commit aafae87

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

src/molecules/link-card/link-card.test.tsx

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from "react";
22
import faker from "faker";
3-
import { LinkCard, IconClassName } from "./link-card";
3+
import { LinkCard, LinkCardIconClassName } from "./link-card";
44
import { TestUtils } from "../../tests/test-utils";
55
import { LinkCardTypes } from "../constants/link-card-types";
66

@@ -16,10 +16,10 @@ describe("LinkCard", () => {
1616
);
1717

1818
//Assert
19-
expect(getByText(expected)).not.toBeNull();
19+
expect(getByText(expected)).not.toBeNil();
2020
});
2121

22-
test("when type prop is button, renders LinkCardTypes.Button", () => {
22+
test(`when type prop is button, renders ${LinkCardTypes.Button}`, () => {
2323
// Arrange
2424
const expected = faker.random.words();
2525
const label = faker.random.words();
@@ -31,14 +31,13 @@ describe("LinkCard", () => {
3131
{expected}
3232
</LinkCard>
3333
);
34-
const result = container.getElementsByTagName(LinkCardTypes.Button)[0];
34+
const result = container.getElementsByTagName("button")[0];
3535

3636
// Assert
37-
expect(result).not.toBeNull();
38-
expect(container.innerHTML).toContain("button");
37+
expect(result).not.toBeNil();
3938
});
4039

41-
test("when default props and include icon, renders with class name -with-icon", () => {
40+
test(`when default props and include icon, renders with class name ${LinkCardIconClassName}`, () => {
4241
// Arrange
4342
const expected = faker.random.words();
4443
const label = faker.random.words();
@@ -49,10 +48,12 @@ describe("LinkCard", () => {
4948
{expected}
5049
</LinkCard>
5150
);
52-
const result = container.getElementsByClassName(IconClassName)[0];
51+
const result = container.getElementsByClassName(
52+
LinkCardIconClassName
53+
)[0];
5354

5455
// Assert
55-
expect(result).not.toBeNull();
56-
expect(result.classList).toContain(IconClassName);
56+
expect(result).not.toBeNil();
57+
expect(result.classList).toContain(LinkCardIconClassName);
5758
});
5859
});

src/molecules/link-card/link-card.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { ParagraphSizes } from "../../atoms/constants/paragraph-sizes";
1313
// -------------------------------------------------------------------------------------------------
1414

1515
const COMPONENT_CLASS = "c-link-card";
16-
export const IconClassName = "-with-icon";
16+
export const LinkCardIconClassName = "-with-icon";
1717

1818
// #endregion Constants
1919

@@ -40,7 +40,7 @@ export interface LinkCardProps {
4040
const LinkCard: React.FC<LinkCardProps> = (props: LinkCardProps) => {
4141
const cssClassNames = [COMPONENT_CLASS];
4242
if (props.includeIcon) {
43-
cssClassNames.push(IconClassName);
43+
cssClassNames.push(LinkCardIconClassName);
4444
}
4545

4646
const cssClassNamesFlat = cssClassNames.join(" ");

0 commit comments

Comments
 (0)