玩笑看到测试套件,但默默地忽略了测试

发布于 2025-02-09 13:29:05 字数 2210 浏览 1 评论 0原文

该问题是指在NUXT/VUE V2项目中的嘲笑测试。单元测试按预期进行,无论是通过还是不通过。经过一些更改后,玩笑停止运行我的测试(既不通过也没有失败)。

----------|---------|----------|---------|---------|-------------------
File      | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
----------|---------|----------|---------|---------|-------------------
All files |       0 |        0 |       0 |       0 |
----------|---------|----------|---------|---------|-------------------
Test Suites: 0 of 10 total
Tests:       0 total
Snapshots:   0 total
Time:        3.454 s, estimated 10 s
Ran all test suites.

我删除了一些我不需要的代码,我藏着更改并再次尝试,但是没有任何测试西服运行。我检查了项目版本,该项目以前按预期进行了测试。仍然什么都没有。

我什至可以做一个空的测试套件,跑步者不会提出“您的测试套件必须至少包含一个测试”例外。这涉及两个测试/单位目录和其他文件夹中的测试。

对于我的提交,我通常有条不紊,但也许我把一些东西弄乱了。我不能排除我在依赖关系树中混合某些东西的可能性,例如,不添加一些至关重要的依赖关系。也许有依赖性不匹配,这是之前没有发生的……

这是什么问题?如何解决此类案例?我以前使用过摩卡咖啡/柴,所以我是新手。

这是我的设置:

jest.config.js

module.exports = {
  moduleNameMapper: {
    "^@/(.*)$": "<rootDir>/$1",
    "^~/(.*)$": "<rootDir>/$1",
    "^vue$": "vue/dist/vue.common.js",
  },
  moduleFileExtensions: ["ts", "js", "vue", "json"],
  transform: {
    "^.+\\.ts$": "ts-jest",
    "^.+\\.js$": "babel-jest",
    ".*\\.(vue)$": "vue-jest",
  },
  collectCoverage: true,
  collectCoverageFrom: [
    "<rootDir>/some-dir/**/*.(js|ts)",
  ],
  testEnvironment: "jsdom",
  testMatch: ["**/*.spec.(js|jsx|ts|tsx)", "**/*.test.(js|jsx|ts|tsx)"],
  runner: "groups",
};

package.json

  "scripts": {
    …
    "test:unit": "jest"
  },
  "dependencies": {
    …
    "core-js": "^2.6.12",
    "nuxt": "^2.15.8",
    "path-to-regexp": "^6.2.1",
    "vue": "^2.6.14",
    "vue-server-renderer": "^2.6.14",
    "vue-template-compiler": "^2.6.14",
    "webpack": "^4.46.0"
  },
  "devDependencies": {
    …
    "@nuxt/types": "^2.15.8",
    "@nuxt/typescript-build": "^2.1.0",
    "@nuxtjs/device": "^2.1.0",
    "@vue/test-utils": "^1.3.0",
    "babel-core": "7.0.0-bridge.0",
    "babel-jest": "^27.4.4",
    "jest": "^27.4.4",
    "jest-runner-groups": "^2.2.0",
    "ts-jest": "^27.1.1",
    "vue-jest": "^3.0.4"
  }
}

The question refers to Jest testing in a Nuxt/Vue v2 project. The unit tests ran as expected, either passing or not passing. After some changes Jest stopped running the tests I had (neither passing nor failing).

----------|---------|----------|---------|---------|-------------------
File      | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
----------|---------|----------|---------|---------|-------------------
All files |       0 |        0 |       0 |       0 |
----------|---------|----------|---------|---------|-------------------
Test Suites: 0 of 10 total
Tests:       0 total
Snapshots:   0 total
Time:        3.454 s, estimated 10 s
Ran all test suites.

I removed some code that I didn’t need, I stashed the changes and tried again, but none of test suits were running. I checked-out to the project version, where the tests previously ran as expected. Still nothing.

I can even make an empty test suite and the runner won’t raise ‘your test suite must contain at least one test’ exception. This involves the tests in both tests/unit directory and in other folders.

I’m usually pretty methodical with regard to my commits, but maybe I messed something up. I cannot exclude a possibility that I mixed something in the dependency tree, e.g. by not adding some crucial dependency to package.json (I removed node_modules and installed it from scratch at some point). Maybe there is a dependency mismatch, which didn’t occur before…

What could be the issue? How to troubleshoot such case? I used Mocha/Chai before so I’m new to Jest.

Here are my settings:

jest.config.js

module.exports = {
  moduleNameMapper: {
    "^@/(.*)
quot;: "<rootDir>/$1",
    "^~/(.*)
quot;: "<rootDir>/$1",
    "^vue
quot;: "vue/dist/vue.common.js",
  },
  moduleFileExtensions: ["ts", "js", "vue", "json"],
  transform: {
    "^.+\\.ts
quot;: "ts-jest",
    "^.+\\.js
quot;: "babel-jest",
    ".*\\.(vue)
quot;: "vue-jest",
  },
  collectCoverage: true,
  collectCoverageFrom: [
    "<rootDir>/some-dir/**/*.(js|ts)",
  ],
  testEnvironment: "jsdom",
  testMatch: ["**/*.spec.(js|jsx|ts|tsx)", "**/*.test.(js|jsx|ts|tsx)"],
  runner: "groups",
};

package.json

  "scripts": {
    …
    "test:unit": "jest"
  },
  "dependencies": {
    …
    "core-js": "^2.6.12",
    "nuxt": "^2.15.8",
    "path-to-regexp": "^6.2.1",
    "vue": "^2.6.14",
    "vue-server-renderer": "^2.6.14",
    "vue-template-compiler": "^2.6.14",
    "webpack": "^4.46.0"
  },
  "devDependencies": {
    …
    "@nuxt/types": "^2.15.8",
    "@nuxt/typescript-build": "^2.1.0",
    "@nuxtjs/device": "^2.1.0",
    "@vue/test-utils": "^1.3.0",
    "babel-core": "7.0.0-bridge.0",
    "babel-jest": "^27.4.4",
    "jest": "^27.4.4",
    "jest-runner-groups": "^2.2.0",
    "ts-jest": "^27.1.1",
    "vue-jest": "^3.0.4"
  }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

赠意 2025-02-16 13:29:06

我将core-js撞到v3,现在起作用。我想我以前是错误地安装了V2(使用 ),然后将其更新为v3,但忘记- 保存标志,因此制动版本控制。

我要离开这个问题,以防它可以帮助某人。

I bumped core-js to v3 and now it works. I suppose that I installed previously v2 by mistake (it used to be nuxt default), then updated it to v3 but forgetting --save flag, hence braking the versioning.

I’m leaving this question in case it helps someone.

心房的律动 2025-02-16 13:29:06

我有同样的问题
我通过升级 @testing-library/react升级到14.0.0来解决它

I had the same problem
I resolved it by upgrading @testing-library/react to 14.0.0

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文