-
Notifications
You must be signed in to change notification settings - Fork 156
Expand file tree
/
Copy pathTestComponent.test.tsx
More file actions
42 lines (34 loc) · 1.23 KB
/
Copy pathTestComponent.test.tsx
File metadata and controls
42 lines (34 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import React from "react";
import { render, within } from "@testing-library/react";
import TestComponent from "./TestComponent";
import { TestComponentProps } from "./TestComponent.types";
describe("TestComponent", () => {
const renderComponent = ({ heading, content }: Partial<TestComponentProps>) =>
render(
<TestComponent
heading={heading || "Default heading text"}
content={content || <div>Default content</div>}
/>
);
it("should render heading text correctly", () => {
const headingText = "Some test heading";
const { getByTestId } = renderComponent({ heading: headingText });
const testComponent = getByTestId("test-component__heading");
expect(testComponent).toHaveTextContent(headingText);
});
it("should render content correctly", () => {
const { getByTestId } = renderComponent({
content: <div data-testid="some-test-content">I am test content</div>,
});
expect(
within(getByTestId("test-component__content")).queryByTestId(
"some-test-content"
)
).toBeInTheDocument();
expect(
within(getByTestId("test-component__content")).queryByTestId(
"some-test-content"
)
).toHaveTextContent("I am test content");
});
});