-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathisland-component.test.tsx
34 lines (29 loc) · 1.1 KB
/
island-component.test.tsx
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
import {
cleanup,
render,
setup,
userEvent,
} from "$fresh-testing-library/components.ts";
import { expect } from "$fresh-testing-library/expect.ts";
import { signal } from "@preact/signals";
import { afterEach, beforeAll, describe, it } from "$std/testing/bdd.ts";
import Counter from "🏝️/Counter.tsx";
import { default as manifest } from "$/fresh.gen.ts";
describe("islands/Counter.tsx", () => {
beforeAll(() => setup({ manifest }));
afterEach(cleanup);
it("should work", async () => {
const count = signal(9);
const user = userEvent.setup();
const screen = render(<Counter count={count} />);
const plusOne = screen.getByRole("button", { name: "+1" });
const minusOne = screen.getByRole("button", { name: "-1" });
expect(screen.getByText("9")).toBeInTheDocument();
await user.click(plusOne);
expect(screen.queryByText("9")).not.toBeInTheDocument();
expect(screen.getByText("10")).toBeInTheDocument();
await user.click(minusOne);
expect(screen.getByText("9")).toBeInTheDocument();
expect(screen.queryByText("10")).not.toBeInTheDocument();
});
});