How to setup unit tests for Nuxt3?

I created a new Nuxt3 app via npx nuxi init <project-name> and want to add unit tests. Based on the docs for 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();
  });
});

When calling vitest --run 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

I also thought about calling nuxt test instead but get this error

Listening http://[::]:38515
[error] ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Failed Suites 1 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
[error]
[error]  FAIL  pages/foo.spec.ts [ pages/foo.spec.ts ]
[error] Error: No test suite found in file /home/.../pages/foo.spec.ts

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?