ReferenceError:测试未用Jest定义

问题描述 投票:1回答:1

我正在尝试用Jest运行最基本的示例,但是我似乎没有能力。请按照此处的说明进行操作:https://jestjs.io/docs/en/getting-started.html

  • npm init -y(对于基础项目)
  • npm install --save-dev开玩笑
  • 创建sum.js文件。
  • 创建sum.test.js文件。
  • 更新“测试”脚本。
  • npm运行测试。

景气,参考错误。我在这里想念什么?

  • npm v6.13.7
  • 节点v10.13.0
  • 笑话v26.0.1

这是我的控制台输出:

FAIL  ./sum.test.js
  ● Test suite failed to run
    ReferenceError: test is not defined
      1 | const sum = require('./sum');
      2 |
    > 3 | test('adds 1 + 2 to equal 3', () => {
        | ^
      4 |   expect(sum(1, 2)).toBe(3);
      5 | });
      at Object.<anonymous> (sum.test.js:3:1)
    Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        0.957 s
Ran all test suites.
(node:21384) ExperimentalWarning: The fs.promises API is experimental
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] test: `jest`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] test script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
node.js jest referenceerror
1个回答
0
投票

似乎与此问题有关:https://github.com/facebook/jest/issues/9538

尝试将节点版本升级到至少v10.14.2或将玩笑降级到至少v25.2.2。

© www.soinside.com 2019 - 2024. All rights reserved.