Any ideas on fixes or how I can continue to troubleshoot this? It works when I run my tests in the console.
node -v: 8.6.0npm -v: 5.5.1
Operating system: Mac OS Sierra 10.12.6
I have jest configured in my package.json with this:
"setupFiles": [
"<rootDir>/config/jest/mockLocalStorage.js"
]
And in mockLocalStorage.js I defined a mockLocalStorage class and then do this: window.localStorage = new LocalStorageMock();
Run the test normally
FAIL src/containers/component.spec.js
โ Test suite failed to run
ReferenceError: window is not defined
at Object.<anonymous> (config/jest/mockLocalStorage.js:16:1)
at <anonymous>
The default testEnvironment is jsdom which should provide window. Are you specifying anything different for the testEnvironment from the command line options or configuration?
That fixed it. I removed it previously but didn't restart vs code. It worked after restart. Thank you!
Thanks @seanpoulter this worked for me.
Most helpful comment
The default
testEnvironmentisjsdomwhich should providewindow. Are you specifying anything different for thetestEnvironmentfrom the command line options or configuration?