簡體   English   中英

Jest 示例測試套件上的 TypeError

[英]TypeError on Jest example test suite

我正在嘗試運行官方文檔提供的 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)

const sum = require('./sum');

test('adds 1 + 2 to equal 3', () => {
  expect(sum(1, 2)).toBe(3);
});

sum.js

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

兩者都在同一個文件夾根/測試

通常,當 package 本身無法運行時,這是因為 package 與其依賴項或節點的版本不匹配。 Jest 正在嘗試使用您的文件中不存在的東西,或者沒有按照 jest 期望的方式工作,這會給您帶來錯誤。 我用 nvm 進行了幾次測試,並在 node v10.* 上遇到了這個開玩笑的錯誤; 您可能想要升級到更新版本的節點或降級 jest。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM