Skip to content
This repository was archived by the owner on Apr 1, 2024. It is now read-only.

Commit 36f95e4

Browse files
authored
Adding UTs for Button Filled (#124)
* Adding UTs for Button Filled Signed-off-by: Sayan Mondal <[email protected]> * Updated Unit Test Approach Signed-off-by: Sayan Mondal <[email protected]> * Removing redundant initialization Signed-off-by: Sayan Mondal <[email protected]>
1 parent 07e2e48 commit 36f95e4

File tree

3 files changed

+1324
-1122
lines changed

3 files changed

+1324
-1122
lines changed

Diff for: package.json

+1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
"@storybook/addons": "^6.3.0",
9090
"@storybook/react": "^6.3.0",
9191
"@storybook/theming": "^6.3.0",
92+
"@testing-library/jest-dom": "^5.14.1",
9293
"@testing-library/react": "^10.0.2",
9394
"@types/d3-array": "^2.3.0",
9495
"@types/jest": "^26.0.24",
+28-8
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,36 @@
1-
import { render } from "@testing-library/react";
1+
import "@testing-library/jest-dom/extend-expect";
2+
import { fireEvent, render, screen } from "@testing-library/react";
23
import React from "react";
34
import { LitmusThemeProvider } from "../../../../theme";
45
import { ButtonFilled } from "../ButtonFilled";
56

6-
describe("Button Filled Component", () => {
7-
it("Renders", () => {
8-
const { getByText } = render(
7+
let component: HTMLElement;
8+
let mockCallBack = jest.fn();
9+
10+
beforeEach(() => {
11+
render(
12+
<LitmusThemeProvider>
913
<LitmusThemeProvider>
10-
<ButtonFilled onClick={() => {}}>Button Filled</ButtonFilled>
14+
<ButtonFilled onClick={mockCallBack}>Button Filled</ButtonFilled>
1115
</LitmusThemeProvider>
12-
);
16+
</LitmusThemeProvider>
17+
);
18+
19+
// Get Button Filled component
20+
component = screen.getByText("Button Filled");
21+
});
22+
23+
test("Renders", () => {
24+
expect(component).toBeTruthy();
25+
});
26+
27+
test("should be clickable", () => {
28+
// Clicking once
29+
fireEvent.click(component);
30+
expect(mockCallBack.mock.calls.length).toEqual(1);
1331

14-
expect(getByText("Button Filled")).toBeTruthy();
15-
});
32+
// Clicking twice
33+
fireEvent.click(component);
34+
fireEvent.click(component);
35+
expect(mockCallBack.mock.calls.length).toEqual(3); // Total three clicks registered on DOM
1636
});

0 commit comments

Comments
 (0)