-1

I am fixing some tests on our pre-existing project, and I ran into this error:

 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)

This is my 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",
}

I tried to search for some fixes online but could not come up with anything

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
JMon
  • 3,387
  • 16
  • 63
  • 102

1 Answers1

1

I guess the problem is your globals.window configuration being set true since code sometimes will try to attempt modify your window object. Try to set it as literal object as below:

"globals": {
  "window": {}
},
tmhao2005
  • 14,776
  • 2
  • 37
  • 44
  • Ok this made that error go away, however it created more test cases to fail. Is that normal? – JMon Aug 05 '20 at 07:02
  • I am thinking that the dev before me added this configuration because of the uiFabric errors – JMon Aug 05 '20 at 07:04
  • Not pretty sure what other cases are but I think setting window as true is not a good idea at all :) we might have to fix others probably – tmhao2005 Aug 05 '20 at 07:07
  • Also you guys have to know which env to test against node/browser so to mock accordingly rather than leaving window as truthy :) – tmhao2005 Aug 05 '20 at 07:22
  • yes, I will have a chat with the other devs to see what is the best way to go around this. Thanks for your help! – JMon Aug 05 '20 at 07:29