我通过
npx nuxi init <project-name>
创建了一个新的 Nuxt3 应用程序,并想添加单元测试。基于测试文档我打电话给npm install -D @nuxt/test-utils vitest
并从./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();
});
});
调用
vitest --run
时出现以下错误
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
我也想过打电话给
nuxt test
但是得到这个错误
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
也许我的设置有误。我找不到有关
的信息