0

跑步时vue-cli-service test:unit 我得到

Test suite failed to run

Cannot find module '@vue/compiler-sfc'

However, Jest was able to find:
../../src/components/component.vue
You might want to include a file extension in your import, or update your 'moduleFileExtensions', which is currently ['ts', 'js', 'vue'].

我收到上述错误。

我的 package.json 中有以下内容

 "devDependencies": {
    "@graphql-codegen/cli": "1.21.5",
    "@graphql-codegen/introspection": "1.18.2",
    "@graphql-codegen/schema-ast": "1.18.2",
    "@graphql-codegen/typescript": "1.22.1",
    "@tailwindcss/ui": "^0.7.2",
    "@testing-library/jest-dom": "^5.11.9",
    "@testing-library/vue": "^5.8.2",
    "@vue/cli-plugin-babel": "~4.5.0",
    "@vue/cli-plugin-eslint": "~4.5.0",
    "@vue/cli-plugin-router": "~4.5.0",
    "@vue/cli-plugin-unit-jest": "~4.5.0",
    "@vue/cli-plugin-vuex": "~4.5.0",
    "@vue/cli-service": "4.5.6",
    "@vue/eslint-config-prettier": "^6.0.0",
    "@vue/test-utils": "^1.2.2",
    "autoprefixer": "^9.8.6",
    "babel-eslint": "^10.1.0",
    "babel-plugin-transform-remove-console": "^6.9.4",
    "cssnano": "^4.1.10",
    "eslint": "^6.7.2",
    "eslint-plugin-graphql": "^4.0.0",
    "eslint-plugin-prettier": "^3.1.3",
    "eslint-plugin-vue": "^6.2.2",
    "graphql-config": "^3.3.0",
    "graphql-tag": "^2.9.0",
    "msw": "^0.35.0",
    "postcss": "^7.0.35",
    "prettier": "^1.19.1",
    "tailwindcss": "npm:@tailwindcss/postcss7-compat@^2.1.2",
    "vue-cli-plugin-apollo": "~0.22.2",
    "vue-jest": "^5.0.0-alpha.10",
    "vue-loader-v16": "16.0.0-beta.5.4",
    "vue-template-compiler": "^2.6.11"
  }

我试过删除我的节点模块,重新安装等。没有运气

下面是我的测试脚本

import Componentfrom "../../src/components/Component";
import { setupServer } from "msw/node";
import { render } from "@testing-library/vue";
import "@testing-library/jest-dom";
import { handlers } from "../../src/mocks/handlers";

const server = setupServer(...handlers);

beforeAll(() => {
  server.listen();
});

afterAll(() => {
  server.close();
});

describe("Component", () => {
  it("should be a new trial User", async () => {
    render(Component);
    // await waitFor(() => {
    //   expect(Component).toContain("Test");
    // });
  });
});
module.exports = {
  preset: "@vue/cli-plugin-unit-jest",
  globals: {
    "ts-jest": {
      tsconfig: "tsconfig.json"
    }
  },
  transform: {
    "^.+\\.vue$": "vue-jest"
  },
  moduleFileExtensions: ["ts", "js", "vue"],
  setupFilesAfterEnv: ["./src/jest.setup.js"]
};

jest.config.js 上面。

我已经安装了 msw 并设置了它的帮助程序/处理程序等,但是当我运行我的测试脚本时,我得到了上面我假设它与我试图导入的 vue 组件有关?其他人在尝试使用 jest 和 vue 时遇到同样的问题或解决了类似的问题?

4

0 回答 0