SolidJS + Testing Library
Test like a user: render, screen, user-event and jest-dom. This page shows exactly what pickstack adds to a SolidJS project for Testing Library: the packages, the new files and the changes to existing ones. Every combination is installed, built, linted and tested in CI.
$ npm create pickstack@latest my-app -- --framework solid --modules testing-library --yesCustomize in the configurator
Packages it adds
| Package | Version | Type |
|---|---|---|
@solidjs/testing-library | ^0.8.10 | dev |
@testing-library/dom | ^10.4.2 | dev |
@testing-library/jest-dom | ^8.0.0 | dev |
@testing-library/user-event | ^14.6.13 | dev |
jsdom | ^31.0.1 | dev |
vitest | ^5.1.1 | dev |
New files
import { render, screen } from "@solidjs/testing-library";
import userEvent from "@testing-library/user-event";
import { describe, expect, it } from "vitest";
import Counter from "./Counter";
describe("Counter", () => {
it("increments when +1 is clicked", async () => {
const user = userEvent.setup();
render(() => <Counter />);
await user.click(screen.getByRole("button", { name: "+1" }));
expect(screen.getByText("1")).toBeInTheDocument();
});
});
import "@testing-library/jest-dom/vitest";
import { cleanup } from "@solidjs/testing-library";
import { afterEach } from "vitest";
afterEach(() => {
cleanup();
});
Changes to existing files
+/// <reference types="vitest/config" /> import { defineConfig } from "vite"; import solid from "vite-plugin-solid"; export default defineConfig({ plugins: [solid()],+ test: {+ environment: "jsdom",+ setupFiles: ["./src/test-setup.ts"],+ }, });
Project files
.gitignoreREADME.mdindex.htmlpackage.jsonsrc/App.tsxsrc/components/Counter.test.tsxsrc/components/Counter.tsxsrc/index.csssrc/index.tsxsrc/test-setup.tstsconfig.app.jsontsconfig.jsontsconfig.node.jsonvite.config.ts