Skip to content

Commit 6513f3c

Browse files
author
Said Shah
committed
Added more tests for increased test coverage
1 parent b4550eb commit 6513f3c

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React from "react";
22
import faker from "faker";
33
import { LinkCard } from "./link-card";
44
import { TestUtils } from "../../tests/test-utils";
5+
import { LinkCardTypes } from "../constants/link-card-types";
56

67
describe("LinkCard", () => {
78
test("When default props, renders LinkCard", () => {
@@ -17,4 +18,42 @@ describe("LinkCard", () => {
1718
//Assert
1819
expect(getByText(expected)).not.toBeNull();
1920
});
21+
22+
test("When type prop is button, renders LinkCard with button", () => {
23+
// Arrange
24+
const expected = faker.random.words();
25+
const label = faker.random.words();
26+
const type = LinkCardTypes.Button;
27+
28+
// Act
29+
const { container } = TestUtils.renderWithRouter(
30+
<LinkCard label={label} type={type}>
31+
{expected}
32+
</LinkCard>
33+
);
34+
const result = container.getElementsByTagName(LinkCardTypes.Button)[0];
35+
36+
// Assert
37+
expect(result).not.toBeNull();
38+
expect(result.classList).toContain("c-button");
39+
expect(container.innerHTML).toContain("button");
40+
});
41+
42+
test("When default props and include icon, renders with class name -with-icon", () => {
43+
// Arrange
44+
const expected = faker.random.words();
45+
const label = faker.random.words();
46+
47+
// Act
48+
const { container } = TestUtils.renderWithRouter(
49+
<LinkCard label={label} includeIcon={true}>
50+
{expected}
51+
</LinkCard>
52+
);
53+
const result = container.getElementsByClassName("-with-icon")[0];
54+
55+
// Assert
56+
expect(result).not.toBeNull();
57+
expect(result.classList).toContain("-with-icon");
58+
});
2059
});

0 commit comments

Comments
 (0)