When trying to use shallow on a component, I get TypeError: Cannot read property 'origin' of undefined at Window.get localStorage. I have ComponentWillMount that is calling to a service that saves to local storage. The trace prints out an issue with JSDOM.
node_modules/jsdom/lib/jsdom/browser/Window.js:256:26
const wrapper = shallow(
System:
OS: macOS 10.14
CPU: x64 Intel(R) Core(TM) i7-7820HQ CPU @ 2.90GHz
Binaries:
Node: 10.3.0 - /usr/local/bin/node
Yarn: 1.7.0 - /usr/local/bin/yarn
npm: 6.1.0 - /usr/local/bin/npm
npmPackages:
jest: 23.6.0 => 23.6.0
Can you include the reproduction steps? Seems like they got cut out
Looks like they did.
I’m simply just using shallow(MyComponent).
What's MyComponent? Please include a more complete example :)
MyComponent is just a component I built that needs to be shallow copied.
In it I call a library for that I believe sets something in LocaLStorage onComponentDidMount.
The test just die because of the aforementioned error just have shallow copying the component, no other code.
Please provide a reproduction we can pull down, run and see the error. I _highly_ doubt this is an issue with Jest, but if it is I'm happy to reopen
Jest is _simply just_ a test runner, it works for me 🤷♂️
@thezachcannon i am facing the same issue..How were you able to fix this?
Hi there. I'm getting these too...
Kind of randomly... After removed node_modules and reinstalling again it stopped for a while, then again.
My project uses localForage (for IndexedDB) and localStorage but this error comes up in unrelated files. I mean: the tests that fail and show this message are not related to localStorage at all.
I'd guess its a JSDOM error but since googling brought me straight here and it's the same error just wanted to add as a +1
I'm still facing the same issue.
For me it worked to use act directly from react-dom/test-utils instead from @testing-library/react. But I really don't know why.
I now have this issue again, very odd. :/
I fixed it by using a mocking library for http requests. In my case i used jest-fetch-mock.
Most helpful comment
Hi there. I'm getting these too...
Kind of randomly... After removed
node_modulesand reinstalling again it stopped for a while, then again.My project uses localForage (for IndexedDB) and localStorage but this error comes up in unrelated files. I mean: the tests that fail and show this message are not related to localStorage at all.
I'd guess its a JSDOM error but since googling brought me straight here and it's the same error just wanted to add as a +1