feat(tests): add fresh-testing-library tests (#1990)

This commit is contained in:
Craig Doremus
2023-11-15 18:25:13 +01:00
committed by GitHub
parent 5d690bede1
commit b5816cd001
20 changed files with 447 additions and 8 deletions
@@ -0,0 +1,47 @@
import { assertEquals, fail } from "$std/testing/asserts.ts";
import { cleanup, render, setup } from "$fresh-testing-library";
import { afterEach, beforeAll, describe, it } from "$std/testing/bdd.ts";
import Header from "$fresh/www/components/gallery/Header.tsx";
describe("components/gallery/Header.tsx", () => {
beforeAll(setup);
afterEach(cleanup);
it("should show 3 links", () => {
const screen = render(<Header active="" />);
const links = screen.getAllByRole("link");
assertEquals(links.length, 3);
});
it("should show '/docs' as active", () => {
const screen = render(<Header active="/docs" />);
const links = screen.getAllByRole("link");
let docsActive = false;
for (const link of links) {
if (link.getAttribute("href") === "/docs") {
if (link.classList.contains("border-b-2")) {
docsActive = true;
}
}
}
if (!docsActive) {
fail("The '/docs' link should be active!!");
}
});
it("should show '/docs' as not active", () => {
const screen = render(<Header active="/" />);
const links = screen.getAllByRole("link");
let docsActive = false;
for (const link of links) {
if (link.getAttribute("href") === "/docs") {
if (link.classList.contains("border-b-2")) {
docsActive = true;
}
}
}
if (docsActive) {
fail("The '/docs' link should NOT be active!!");
}
});
});