javascript - Jest : ReferenceError: describe is not defined

标签 javascript jestjs

我尝试按照本教程为我的项目设置 Jest :https://dev.to/nedsoft/testing-nodejs-express-api-with-jest-and-supertest-1km6

但是当我尝试运行基本测试时出现以下错误:

 FAIL  tests/sample.test.js
  ● Test suite failed to run

    ReferenceError: describe is not defined

    > 1 | describe('Sample Test', () => {
        | ^
      2 |     it('should test that true === true', () => {
      3 |         expect(true).toBe(true)
      4 |     })

      at Object.<anonymous> (tests/sample.test.js:1:1)

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        1.521 s
Ran all test suites.
(node:15452) ExperimentalWarning: The fs.promises API is experimental
npm ERR! Test failed.  See above for more details.

我尝试在我的 package.json 中删除:

testEnvironment: 'node',

但没有任何改变。

一个想法?

最佳答案

好的,问题是 jest 的最新版本与节点 10.13.0 有冲突

来源:https://github.com/facebook/jest/issues/9538

所以做这个就可以了:

npm install --save-dev jest@25.2.2 supertest

关于javascript - Jest : ReferenceError: describe is not defined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61912996/

相关文章:

reactjs - 模拟意味着在 1 个节点上运行 = 0 找到

javascript - JS从循环中提取目标并在外部工作

javascript - __proto__ javascript 中构造函数的无限嵌套

javascript - php header 位置未重定向,也没有错误

javascript - 等待 socket.on ('answerToRequest' ) 可以使用 Socket.io 吗?

javascript - JestJS:如何获得模拟函数的不同 promise 结果并测试抛出的错误?

javascript - 在 React 模块中测试 SweetAlert2 的 preConfirm Hook

javascript - 如何从 USB 端口向 HTML 网站发送信号?

javascript - 如何更改模拟导入的行为?

javascript - 使用 bootstrap-vue 运行 jest 时出现问题