I’m trying to write tests for all my JS, and the tests (I’m using Jasmine) are run locally in the browser. Due to security restraints(?) sessionStorage does not work locally (viewing file:///… in the browser) in Firefox.
Quick example:
window.sessionStorage.setItem('foo', 'bar');
This gives “Error: Operation is not supported”.
I tried overriding window.sessionStorage with my own mock methods, but with no luck.
The only solution I have at the moment is to put everything related to sessionStorage inside a try/catch block.
Any suggestions for how to best handle this issue?
Object.definePropertyseems to work with this, you can mocksessionStorageuse it:but this mockup doesn’t work with the indexer of
sessionStorage(window.sessionStorage[key] = value) Proxy to build themockupobject.