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 --yesCustomize in the configurator
Packages it adds
| Package | Version | Type |
|---|---|---|
@types/jsdom | ^30.0.0 | dev |
@vue/test-utils | ^2.6.0 | dev |
jsdom | ^31.0.1 | dev |
vitest | ^5.1.1 | dev |
New files
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");
});
});
{
"extends": "./tsconfig.app.json",
"include": ["src/**/__tests__/*", "env.d.ts"],
"exclude": [],
"compilerOptions": {
"lib": [],
"types": ["node", "jsdom"],
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.vitest.tsbuildinfo"
}
}
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
⋯ 5 unchanged lines }, { "path": "./tsconfig.app.json"+ },+ {+ "path": "./tsconfig.vitest.json" } ] }⋯ 1 unchanged lines
Project files
.gitignoreREADME.mdenv.d.tsindex.htmlpackage.jsonsrc/App.vuesrc/assets/main.csssrc/components/CounterCard.vuesrc/components/__tests__/CounterCard.spec.tssrc/main.tstsconfig.app.jsontsconfig.jsontsconfig.node.jsontsconfig.vitest.jsonvite.config.tsvitest.config.ts