我正在尝试使用 Jest 运行最基本的示例,但我似乎无法做到。 按照此处的说明进行操作:https://jestjs.io/docs/en/getting-started.html
- npm init -y(对于基础项目)
- npm install --save-dev Jest
- 创建 sum.js 文件。
- 创建 sum.test.js 文件。
- 更新“测试”脚本。
- npm 运行测试。
繁荣,引用错误。我在这里缺少什么?
- npm v6.13.7
- Node v10.13.0
- Jest 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! <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2e5a4b5d5a6e1f001e001e" rel="noreferrer noopener nofollow">[email protected]</a> test: `jest`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c2b6a7b1b682f3ecf2ecf2" rel="noreferrer noopener nofollow">[email protected]</a> test script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
最佳答案
似乎与此问题相关:https://github.com/facebook/jest/issues/9538
尝试将您的 Node 版本升级到至少 v10.14.2 或将 jest 降级到最多 v25.2.2。
关于node.js - ReferenceError:未使用 Jest 定义测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62031536/