How to deal with sessionStorage locally in FF (for testing)

别说谁变了你拦得住时间么 提交于 2019-12-06 02:54:31

Object.defineProperty seems to work with this, you can mock sessionStorage use it:

var mockup = function() {
  var table = {};
  return {
    getItem: function(key) {
      return table[key];
    },
    setItem: function(key, value) {
      table[key] = value.toString();
    },
    clear: function() {
      table = {};
    }
  };
}();
Object.defineProperty(window, 'sessionStorage', { value: mockup });
// should output "Object { getItem=function(), setItem=function(), clear=function()}"
console.log(window.sessionStorage);

but this mockup doesn't work with the indexer of sessionStorage (window.sessionStorage[key] = value) Proxy to build the mockup object.

You get local mocking automatically if you use: http://nbubna.github.io/store/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!