Skip to content

Commit 82012c4

Browse files
committed
refactor: remove the getComponent function
1 parent 98b8c13 commit 82012c4

File tree

2 files changed

+15
-33
lines changed

2 files changed

+15
-33
lines changed

packages/web-components/src/button/standard/button.test.tsx

+14-18
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { describe, expect, it, jest } from "@jest/globals";
55
import { createComponent } from "@lit/react";
66
import React, { type FormEventHandler } from "react";
77
import {
8-
getComponent,
98
itShouldMount,
109
itSupportsClassName,
1110
itSupportsDataSetProps,
@@ -19,6 +18,7 @@ const Button = createComponent({
1918
});
2019

2120
const handleClick = jest.fn();
21+
const getTestButton = () => screen.getByTestId("test-button");
2222

2323
const mockRequiredProps = {
2424
label: "test-button-label",
@@ -31,9 +31,8 @@ describe("🧪 button/standard: UI", () => {
3131
itSupportsDataSetProps(Button, mockRequiredProps);
3232

3333
it("should trigger `handleClick` function after clicking on the button", async () => {
34-
const testButton = getComponent(Button, {
35-
onClick: handleClick,
36-
});
34+
render(<Button onClick={handleClick} />);
35+
const testButton = getTestButton();
3736

3837
const { click } = userEvent.setup();
3938

@@ -43,9 +42,8 @@ describe("🧪 button/standard: UI", () => {
4342
});
4443

4544
it("should trigger `handleClick` function after focusing on the button and pressing Enter", async () => {
46-
const testButton = getComponent(Button, {
47-
onClick: handleClick,
48-
});
45+
render(<Button onClick={handleClick} />);
46+
const testButton = getTestButton();
4947

5048
const { tab, keyboard } = userEvent.setup();
5149

@@ -57,10 +55,13 @@ describe("🧪 button/standard: UI", () => {
5755
});
5856

5957
it("should not be able to trigger `handleClick` function while `disabled`", async () => {
60-
const testButton = getComponent(Button, {
61-
onClick: handleClick,
62-
disabled: true,
63-
});
58+
render(
59+
<Button
60+
onClick={handleClick}
61+
disabled
62+
/>,
63+
);
64+
const testButton = getTestButton();
6465

6566
const { tab, click } = userEvent.setup();
6667

@@ -72,13 +73,8 @@ describe("🧪 button/standard: UI", () => {
7273
expect(handleClick).toHaveBeenCalledTimes(0);
7374
});
7475

75-
it("should have `aria-label` property when the host has a `label` property", async () => {
76-
render(
77-
<Button
78-
{...mockRequiredProps}
79-
label="test-label"
80-
/>,
81-
);
76+
it("should have `aria-label` when the host has a `label` property", async () => {
77+
render(<Button label="test-label" />);
8278

8379
expect(
8480
await screen.findByShadowTestId("tapsi-button-root"),

packages/web-components/src/internals/tests.tsx

+1-15
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,7 @@
1-
import { render, screen } from "@internals/test-helpers";
1+
import { render } from "@internals/test-helpers";
22
import { expect, it } from "@jest/globals";
33
import { type ComponentType } from "react";
44

5-
export const getComponent = <T extends JSX.IntrinsicAttributes>(
6-
Component: ComponentType<T>,
7-
props: T,
8-
): HTMLElement => {
9-
render(
10-
<Component
11-
data-testid="test-component"
12-
{...props}
13-
/>,
14-
);
15-
16-
return screen.getByTestId("test-component");
17-
};
18-
195
export const itShouldMount = <T extends JSX.IntrinsicAttributes>(
206
Component: ComponentType<T>,
217
requiredProps: T,

0 commit comments

Comments
 (0)