-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathComponent.test.tsx
More file actions
46 lines (42 loc) · 1.23 KB
/
Component.test.tsx
File metadata and controls
46 lines (42 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
43
44
45
46
import { describe, it, expect, beforeEach, afterEach } from "vitest";
import { render, screen } from "@testing-library/react";
import { Component } from "./Component";
import { registry } from "@/components/registry";
import type { FC } from "react";
describe("Component", () => {
beforeEach(() => {
registry.clear();
});
afterEach(() => {
registry.clear();
});
it("should not render unknown Component types", () => {
const boxProps = {
type: "Box",
id: "bx",
children: ["Hello!", "World!"],
onChange: () => {},
};
render(<Component {...boxProps} />);
// to inspect rendered component, do:
// expect(document.body).toEqual({});
expect(document.querySelector("#bx")).toBe(null);
});
it("should render a known component", () => {
interface DivProps {
text: string;
}
const Div: FC<DivProps> = ({ text }) => <div>{text}</div>;
registry.register("Div", Div);
const divProps = {
type: "Div",
id: "root",
text: "Hello!",
onChange: () => {},
};
render(<Component {...divProps} />);
// to inspect rendered component, do:
// expect(document.body).toEqual({});
expect(screen.getByText("Hello!")).not.toBeUndefined();
});
});