Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Jest示例测试套件上的TypeError_Javascript_Jestjs - Fatal编程技术网

Javascript Jest示例测试套件上的TypeError

Javascript Jest示例测试套件上的TypeError,javascript,jestjs,Javascript,Jestjs,我正在尝试运行官方文档提供的jest测试套件,它在终端中给出了以下错误 FAIL test/sum.test.js ● Test suite failed to run TypeError: (0 , _vm(...).compileFunction) is not a function at Runtime._execModule (node_modules/jest-runtime/build/index.js:1166:56) Test Suites: 1

我正在尝试运行官方文档提供的jest测试套件,它在终端中给出了以下错误

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

    TypeError: (0 , _vm(...).compileFunction) is not a function

      at Runtime._execModule (node_modules/jest-runtime/build/index.js:1166:56)

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        1.041 s
Ran all test suites.
(node:15186) ExperimentalWarning: The fs.promises API is experimental
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! PhotoGallery@1.0.0 test: `jest`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the PhotoGallery@1.0.0 test script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
以下是我的测试文件(sum.test.js)

sum.js

function sum(a, b) {
  return a + b;
}
module.exports = sum;

当包本身由于包与其依赖项或节点的版本不匹配而无法运行时,它们都位于同一文件夹root/test

。Jest试图使用文件中不存在的东西,或者没有按照Jest期望的方式工作,这会给您带来错误。我使用nvm运行了几个测试,并在节点v10中得到了这个jest错误。*;您可能需要升级到更新版本的node或降级jest

function sum(a, b) {
  return a + b;
}
module.exports = sum;