Jest 测试套件未能 运行

Jest Test suite failed to run

我正在尝试将 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/expect 块。我也尝试将 test 更改为 it 但没有效果。

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

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