N
Nuxt3y ago
Garzec

How to setup tests?

I created a new Nuxt3 app via npx nuxi init <project-name> and want to add unit tests. Based on https://nuxt.com/docs/getting-started/testing I called npm install -D @nuxt/test-utils vitest and started with ./pages/foo.spec.ts
import { describe, it, expect } from "vitest";
import { setup } from "@nuxt/test-utils";

describe("Suite", async () => {
await setup();

it("passes", () => {
expect(true).toBeTruthy();
});
});
import { describe, it, expect } from "vitest";
import { setup } from "@nuxt/test-utils";

describe("Suite", async () => {
await setup();

it("passes", () => {
expect(true).toBeTruthy();
});
});
When calling vitest --run as a npm script I get the following error
TypeError: Cannot read properties of undefined (reading 'on')
❯ setupVitest ../../node_modules/@nuxt/test-utils/dist/index.mjs:138:10
137| setTestContext(void 0);
138| };
139| const afterAll = async () => {
| ^
140| if (ctx.serverProcess) {
141| setTestContext(ctx);
❯ Module.setup ../../node_modules/@nuxt/test-utils/dist/index.mjs:197:3
❯ pages/foo.spec.ts:5:3
TypeError: Cannot read properties of undefined (reading 'on')
❯ setupVitest ../../node_modules/@nuxt/test-utils/dist/index.mjs:138:10
137| setTestContext(void 0);
138| };
139| const afterAll = async () => {
| ^
140| if (ctx.serverProcess) {
141| setTestContext(ctx);
❯ Module.setup ../../node_modules/@nuxt/test-utils/dist/index.mjs:197:3
❯ pages/foo.spec.ts:5:3
Maybe my setup is wrong. I wasn't able to find information about - Where to put the tests? - How to call the tests via npm scripts?
Nuxt
Testing · Get Started with Nuxt
How to test your Nuxt application.
1 Reply
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View

Did you find this page helpful?