簡體   English   中英

React + Jest:測試套件無法運行

[英]React + Jest: Test suite failed to run

我正在修復我們預先存在的項目的一些測試,我遇到了這個錯誤:

 FAIL  src/components/changelog/__test__/ChangeLogOverView.test.tsx
  ● Test suite failed to run

    TypeError: Cannot create property '__packages__' on boolean 'true'

      at Object.setVersion (node_modules/@uifabric/set-version/src/setVersion.ts:7:51)
      at Object.<anonymous> (node_modules/@uifabric/set-version/src/index.ts:4:1)
      at Object.<anonymous> (node_modules/office-ui-fabric-react/src/version.ts:3:3)

這是我的 jest.config.js:

module.exports = {
    "name": "",
    // Setup Jest
    "roots": [
        "<rootDir>/src"
    ],
    "testEnvironment": "node",
    "transformIgnorePatterns": ["/node_modules/"],
    "transform": {
        "^.+\\.tsx?$": "ts-jest"
    },
    "testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$",
    "moduleNameMapper": {
        'office-ui-fabric-react/lib/(.*)$': 'office-ui-fabric-react/lib-commonjs/$1'
    },
    "moduleFileExtensions": [
        "ts",
        "tsx",
        "js",
        "jsx",
        "json",
        "node"
    ],
    "globals": {
        "window": true
    },
    // Setup Enzyme
    "snapshotSerializers": ["enzyme-to-json/serializer"],
    "setupTestFrameworkScriptFile": "<rootDir>/src/setupEnzyme.ts",
}

我試圖在網上搜索一些修復程序,但無法提出任何問題

我想問題是你的globals.window配置設置為true ,因為代碼有時會嘗試修改你的 window object。 嘗試將其設置為文字 object 如下:

"globals": {
  "window": {}
},

暫無
暫無

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

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