Skip to content

memory.js

Carl's edited this page May 27, 2021 · 4 revisions

memory.js 单元测试

memory.js

setItem && getItem:

case 1

        setItem{
         zh:"你好",
         key:"nihao"
     })
  • test
    getItem("nihao")
  • return
       {
         zh:"你好",
         order:0
         key:"nihao"
      }

case 2:

       localStorage.clear();
       setItem{
         zh:"你好",
         key:"nihao"
      });
     setItem{
         zh:"你好",
         key:"nihao"
      });
  • test
    getItem("nihao")
  • return
       {
         zh:"你好",
         order:2
         key:"nihao"
      }

case 3 (清理超过七天,order还是为0的热词):

       localStorage.clear();
       setItem{
         zh:"你好",
         key:"nihao"
      });
     try{
       let t= localStorage.getItem("vue-keyboard-cn-store");
       let parseJons=JSON.parse(t);
       parseJons["__$lastClearTime"]=new Date().getTime()-(86400*7);
       let stringStore=JSON.string(parseJons["__$lastClearTime"]);
       localStorage.setItem("vue-keyboard-cn-store",stringStore);
       
     }catch(e){}

      setItem{
         zh:"哈喽",
         key:"halou"
      });
  • test
    getItem("nihao")
  • return
       {}