pickstack

Vue + Vitest

Vite-native test runner, with a sample counter component test. This page shows exactly what pickstack adds to a Vue project for Vitest: 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 vue --modules vitest --yes
Customize in the configurator

Packages it adds

PackageVersionType
@types/jsdom^30.0.0dev
@vue/test-utils^2.6.0dev
jsdom^31.0.1dev
vitest^5.1.1dev

New files

src/components/__tests__/CounterCard.spec.ts
import { mount } from "@vue/test-utils";
import { describe, expect, it } from "vitest";
import CounterCard from "../CounterCard.vue";

describe("CounterCard", () => {
  it("increments when +1 is clicked", async () => {
    const wrapper = mount(CounterCard);

    const plus = wrapper.findAll("button").find((b) => b.text() === "+1");
    await plus?.trigger("click");

    expect(wrapper.get("p").text()).toBe("1");
  });
});
tsconfig.vitest.json
{
  "extends": "./tsconfig.app.json",
  "include": ["src/**/__tests__/*", "env.d.ts"],
  "exclude": [],
  "compilerOptions": {
    "lib": [],
    "types": ["node", "jsdom"],
    "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.vitest.tsbuildinfo"
  }
}
vitest.config.ts
import { fileURLToPath } from "node:url";
import { defineConfig, mergeConfig } from "vitest/config";
import viteConfig from "./vite.config.ts";

export default mergeConfig(
  viteConfig,
  defineConfig({
    test: {
      environment: "jsdom",
      root: fileURLToPath(new URL("./", import.meta.url)),
    },
  }),
);

Changes to existing files

tsconfig.json (changed)
⋯ 5 unchanged lines     },     {       "path": "./tsconfig.app.json"+    },+    {+      "path": "./tsconfig.vitest.json"     }   ] }⋯ 1 unchanged lines

Project files

Related templates