My App is using localStorage but when I run tests, I get this error:
ReferenceError: localStorage is not defined
Should we provide a polyfill to be able to mock it with Jest ?
Workaround
Add a --setupTestFrameworkScriptFile ./localStoragePolyfill.js to the test command in package.json, where ./localStoragePolyfill looks like this:
constlocalStorageMock=(()=>{letstore={}return{getItem(key){returnstore[key]},setItem(key,value){store[key]=value.toString()},clear(){store={}}};})()global.localStorage=localStorageMockI guess it should be added to config/polyfills.js.
I can PR if that's fine. Not sure if we should use a simple inline polyfill or use something like node-localstorage though.
My App is using
localStoragebut when I run tests, I get this error:ReferenceError: localStorage is not definedShould we provide a polyfill to be able to mock it with Jest ?
Workaround
Add a
--setupTestFrameworkScriptFile ./localStoragePolyfill.jsto thetestcommand inpackage.json, where./localStoragePolyfilllooks like this:I guess it should be added to config/polyfills.js.
I can PR if that's fine. Not sure if we should use a simple inline polyfill or use something like
node-localstoragethough.