octo3.
octo3.15mo ago

Is the Fresh compornents test function enabled?

Attempting to write a test for Fresh compornents. I was able to verify the rendered content. I am not able to validate the event. I would appreciate any help if anyone has a solution. Here is the source code.
// 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());
});
});
Here is the execution command.
deno test --allow-env --no-check
deno test --allow-env --no-check
Here is the execution result.(Excerpt)
$deno test --allow-env --no-check
ERRORS
Counter Component => ./test/islands/Counter_test.tsx:8:6
error: Error: The given node is not an Element, the node type is: object.
at Pe (https://esm.sh/v127/@testing-library/dom@8.20.1/denonext/dom.mjs:7:1421)
at _ (https://esm.sh/v127/@testing-library/dom@8.20.1/denonext/dom.mjs:43:9839)
at Function.v.<computed> [as click] (https://esm.sh/v127/@testing-library/preact@3.2.3/X-ZC9wcmVhY3RAMTAuMTUuMQ/denonext/preact.mjs:3:1149)
at file:///D:/development/test/test428-fresh-test/test/islands/Counter_test.tsx:22:13
$deno test --allow-env --no-check
ERRORS
Counter Component => ./test/islands/Counter_test.tsx:8:6
error: Error: The given node is not an Element, the node type is: object.
at Pe (https://esm.sh/v127/@testing-library/dom@8.20.1/denonext/dom.mjs:7:1421)
at _ (https://esm.sh/v127/@testing-library/dom@8.20.1/denonext/dom.mjs:43:9839)
at Function.v.<computed> [as click] (https://esm.sh/v127/@testing-library/preact@3.2.3/X-ZC9wcmVhY3RAMTAuMTUuMQ/denonext/preact.mjs:3:1149)
at file:///D:/development/test/test428-fresh-test/test/islands/Counter_test.tsx:22:13
3 Replies
Deno AI Helper
Deno AI Helper15mo ago
Oops, our Deno bot encountered a dino-sized hiccup. We're on it - retry soon!
cdoremus
cdoremus15mo ago
You might want to try fresh-testing-library: https://deno.land/x/fresh_testing_library
octo3.
octo3.OP14mo ago
@cdoremus Thanks, I'll give this a try.