Skip to content

Commit 77274ed

Browse files
test(badge-button-web): migrate tests to use react-testing-library and remove enzyme
1 parent 9fc3bc4 commit 77274ed

File tree

4 files changed

+52
-51
lines changed

4 files changed

+52
-51
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
...require("@mendix/pluggable-widgets-tools/test-config/jest.enzyme-free.config.js")
3+
};

packages/pluggableWidgets/badge-button-web/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"publish-marketplace": "rui-publish-marketplace",
3838
"release": "cross-env MPKOUTPUT=BadgeButton.mpk pluggable-widgets-tools release:web",
3939
"start": "cross-env MPKOUTPUT=BadgeButton.mpk pluggable-widgets-tools start:server",
40-
"test": "pluggable-widgets-tools test:unit:web",
40+
"test": "jest --projects jest.config.js",
4141
"update-changelog": "rui-update-changelog-widget",
4242
"verify": "rui-verify-package-format"
4343
},

packages/pluggableWidgets/badge-button-web/src/components/__tests__/BadgeButton.spec.ts

Lines changed: 0 additions & 50 deletions
This file was deleted.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import "@testing-library/jest-dom";
2+
import { render, RenderResult } from "@testing-library/react";
3+
import userEvent from "@testing-library/user-event";
4+
import { createElement } from "react";
5+
6+
import { BadgeButton, BadgeButtonProps } from "../BadgeButton";
7+
8+
describe("BadgeButton", () => {
9+
function renderBadgeButton(props: Partial<BadgeButtonProps>): RenderResult {
10+
return render(<BadgeButton {...props} />);
11+
}
12+
13+
it("renders the structure correctly", () => {
14+
const badgeProps: BadgeButtonProps = {
15+
label: "Custom Label",
16+
onClick: jest.fn(),
17+
value: "0"
18+
};
19+
20+
const badge = renderBadgeButton(badgeProps);
21+
22+
const button = badge.getByRole("button", { name: /custom label/i });
23+
expect(button).toHaveClass("widget-badge-button btn btn-primary");
24+
25+
const label = badge.getByText("Custom Label");
26+
expect(label).toHaveClass("widget-badge-button-text");
27+
28+
const badgeValue = badge.getByText("0");
29+
expect(badgeValue).toHaveClass("badge");
30+
});
31+
32+
it("responds to click events", async () => {
33+
const user = userEvent.setup();
34+
const onClickMock = jest.fn();
35+
const badgeProps: BadgeButtonProps = { onClick: onClickMock };
36+
const badge = renderBadgeButton(badgeProps);
37+
38+
await user.click(badge.getByRole("button"));
39+
40+
expect(onClickMock).toHaveBeenCalled();
41+
});
42+
43+
it("renders correctly with custom classes", () => {
44+
const badge = renderBadgeButton({ className: "btn-secondary" });
45+
46+
expect(badge.getByRole("button")).toHaveClass("btn btn-secondary");
47+
});
48+
});

0 commit comments

Comments
 (0)