// test/islands/Counter_test.tsx
import { DOMParser } from "https://deno.land/x/deno_dom/deno-dom-wasm.ts";
import { assertEquals } from "https://deno.land/std@0.203.0/testing/asserts.ts";
import { fireEvent, render } from "https://esm.sh/@testing-library/preact?deps=preact@10.15.1";
import { waitFor } from "https://esm.sh/@testing-library/dom";
import Counter from "../../islands/Counter.tsx";
import { signal } from "@preact/signals";
Deno.test("Counter Component", async () => {
const document = new DOMParser().parseFromString(
"<!DOCTYPE html>",
"text/html",
)!;
globalThis.document = document;
window.document = document;
const count = signal(3);
const { container, getByText } = render(<Counter count={count} />);
const counter = container.querySelector("p")!;
assertEquals(counter.textContent, count.value.toString());
fireEvent.click(getByText("-1"));
await waitFor(() => {
assertEquals(counter.textContent, count.value.toString());
});
});
// test/islands/Counter_test.tsx
import { DOMParser } from "https://deno.land/x/deno_dom/deno-dom-wasm.ts";
import { assertEquals } from "https://deno.land/std@0.203.0/testing/asserts.ts";
import { fireEvent, render } from "https://esm.sh/@testing-library/preact?deps=preact@10.15.1";
import { waitFor } from "https://esm.sh/@testing-library/dom";
import Counter from "../../islands/Counter.tsx";
import { signal } from "@preact/signals";
Deno.test("Counter Component", async () => {
const document = new DOMParser().parseFromString(
"<!DOCTYPE html>",
"text/html",
)!;
globalThis.document = document;
window.document = document;
const count = signal(3);
const { container, getByText } = render(<Counter count={count} />);
const counter = container.querySelector("p")!;
assertEquals(counter.textContent, count.value.toString());
fireEvent.click(getByText("-1"));
await waitFor(() => {
assertEquals(counter.textContent, count.value.toString());
});
});