【问题标题】:Jest Test suite failed to runJest 测试套件无法运行
【发布时间】:2022-01-05 22:06:57
【问题描述】:

我正在尝试将 Jest 测试添加到 vanilla JS 项目中。我用 npm 安装了 Jest,并创建了一个示例测试文件:

// file example.test.js
const { expect } = require("@jest/globals");
const { test } = require("jest-circus");

const one = 1;

test("example test", () => {
  expect(one).toBe(1);
});

但我收到以下错误:

 FAIL  ./example.test.js
  ● Test suite failed to run

    Your test suite must contain at least one test.

      at onResult (node_modules/@jest/core/build/TestScheduler.js:175:18)
          at Array.map (<anonymous>)

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        0.437 s
Ran all test suites.

不确定可能有什么问题?我显然在测试文件中有一个测试/预期块。我也尝试将test 更改为it,但没有效果。

【问题讨论】:

  • 您缺少describe 代码块。

标签: javascript unit-testing jestjs


【解决方案1】:

您应该从@jest/globals 包中导入test 函数。

const { expect, test } = require('@jest/globals');

【讨论】:

  • 这是正确的答案。在我的情况下,自动完成尝试从“jest-circus”导入test,而它应该是“@jest/globals”。
猜你喜欢
  • 2019-10-21
  • 2020-11-25
  • 2020-09-22
  • 1970-01-01
  • 2019-10-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-10-14
相关资源
最近更新 更多