I have a craco project that runs just fine, but when running tests with jest it throws the following error. I don't even have jsdom installed, it appears to be a peer dependency of craco? No idea how to solve this one, but can clarify any questions in the comments since I don't know what is causing this.
/Users/munsterberg/code/creatordao/creatordao-portal/node_modules/jsdom/lib/jsdom/living/xhr/XMLHttpRequest-impl.js:111
referrer: _ownerDocument.URL,
^
TypeError: Cannot read properties of null (reading 'URL')
at new XMLHttpRequestImpl (/Users/munsterberg/code/creatordao/creatordao-portal/node_modules/jsdom/lib/jsdom/living/xhr/XMLHttpRequest-impl.js:111:32)
at Object.exports.setup (/Users/munsterberg/code/creatordao/creatordao-portal/node_modules/jsdom/lib/jsdom/living/generated/XMLHttpRequest.js:62:12)
at new XMLHttpRequest (/Users/munsterberg/code/creatordao/creatordao-portal/node_modules/jsdom/lib/jsdom/living/generated/XMLHttpRequest.js:101:22)
at /Users/munsterberg/code/creatordao/creatordao-portal/node_modules/whatwg-fetch/dist/fetch.umd.js:514:17
at new Promise (<anonymous>)
at fetch (/Users/munsterberg/code/creatordao/creatordao-portal/node_modules/whatwg-fetch/dist/fetch.umd.js:507:12)
at /Users/munsterberg/code/creatordao/creatordao-portal/node_modules/@firebase/installations/src/functions/create-installation-request.ts:54:51
at /Users/munsterberg/code/creatordao/creatordao-portal/node_modules/@firebase/installations/src/functions/common.ts:94:24
at step (/Users/munsterberg/code/creatordao/creatordao-portal/node_modules/@firebase/installations/node_modules/tslib/tslib.js:143:27)
at Object.next (/Users/munsterberg/code/creatordao/creatordao-portal/node_modules/@firebase/installations/node_modules/tslib/tslib.js:124:57)
I noticed firebase is a part of the stack trace. Is it possible this is related?
After hours of debugging I found out it was related to the getAnalytics function exported from the firebase/analytics package. The fix for me was to mock the getAnalytics function as it wasn't required for testing purposes anyways.
Just a few tips for future uses:
at /Users/munsterberg/code/creatordao/creatordao-portal/node_modules/@firebase/installations/src/functions/create-installation-request.ts:54:51
at /Users/munsterberg/code/creatordao/creatordao-portal/node_modules/@firebase/installations/src/functions/common.ts:94:24
at step (/Users/munsterberg/code/creatordao/creatordao-portal/node_modules/@firebase/installations/node_modules/tslib/tslib.js:143:27)
at Object.next (/Users/munsterberg/code/creatordao/creatordao-portal/node_modules/@firebase/installations/node_modules/tslib/tslib.js:124:57)
Here @firebase package is mentioned quite a few times, functions too, so you can deduce it has something to with it, especially with it under node_module.
mock functions, which are:special functions that allow us to track how a particular function is called by external code
So mocking a function can actually be important, especially when running tests with external packages and files.
Related:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With