Nuxt + Vitest
Vite-native test runner, with a sample counter component test. This page shows exactly what pickstack adds to a Nuxt 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 nuxt --modules vitest --yesCustomize in the configurator
Packages it adds
| Package | Version | Type |
|---|---|---|
@nuxt/test-utils | ^4.4.0 | dev |
@vue/test-utils | ^2.6.0 | dev |
happy-dom | ^21.0.4 | dev |
vitest | ^5.1.1 | dev |
New files
import { mountSuspended } from "@nuxt/test-utils/runtime";
import { describe, expect, it } from "vitest";
import CounterCard from "~/components/CounterCard.vue";
describe("CounterCard", () => {
it("increments when +1 is clicked", async () => {
const wrapper = await mountSuspended(CounterCard);
const plus = wrapper.findAll("button").find((b) => b.text() === "+1");
await plus?.trigger("click");
expect(wrapper.get("p").text()).toBe("1");
});
});
import { defineVitestProject } from "@nuxt/test-utils/config";
import { defineConfig } from "vitest/config";
export default defineConfig({
test: {
projects: [
await defineVitestProject({
test: {
name: "nuxt",
include: ["test/nuxt/*.{test,spec}.ts"],
environment: "nuxt",
},
}),
],
},
});
Changes to existing files
<template> <section class="page"> <h1 class="title">About</h1>+ <p class="text">Built with Nuxt 4, Vue 3, TypeScript, Vitest.</p>− <p class="text">Built with Nuxt 4, Vue 3, TypeScript.</p> </section> </template>
Project files
.gitignoreREADME.mdapp/app.vueapp/assets/css/main.cssapp/components/CounterCard.vueapp/pages/about.vueapp/pages/index.vuenuxt.config.tspackage.jsonpublic/robots.txttest/nuxt/CounterCard.test.tstsconfig.jsonvitest.config.ts