UNPKG

mm-utils

Version:

mm-utils,JavaScript工具包,日常开发工作常用的公共函数库

76 lines (63 loc) 2.5 kB
// 单元测试:缓存相关处理库 import storage from "../src/storage"; import Cookies from "js-cookie"; describe("storage:缓存相关处理库", function () { test("setStorage:localStorage存值", () => { storage.setStorage("age", "33"); expect(storage.getStorage("age")).toBe("33"); }); test("getStorage:localStorage取值", () => { //在浏览器中测试OK storage.setStorage("name", "小明"); expect(storage.getStorage("name")).toBe("小明"); }); test("removeStorage:删除localStorage值", () => { //在浏览器中测试OK let source = storage.setStorage("class", "幼儿园4班") let target = storage.removeStorage("class"); expect(source).toBe(target); }); test("clearStorage:清除所有localStorage存值", () => { //在浏览器中测试OK expect(storage.clearStorage()).toBe("数据已清空"); }); test("setSession:sessionStorage存值", () => { //在浏览器中测试OK storage.setSession("age1", "22"); expect(storage.getSession("age1")).toBe("22"); }); test("getSession:sessionStorage取值", () => { //在浏览器中测试OK storage.setSession("name1", "程咬金"); expect(storage.getSession("name1")).toBe("程咬金"); }); test("removeSession:删除sessionStorage值", () => { //在浏览器中测试OK storage.setSession("class1", "幼儿园二班"); expect(storage.removeSession("class1")).toBe(undefined); }); test("clearSession:清除所有sessionStorage存值", () => { //在浏览器中测试OK expect(storage.clearSession()).toBe("数据已清空"); }); test("setCookie:cookie存值", () => { //在VSCode测试OK,浏览器没有安装js-Cookies无法测试 storage.setCookie("age2", "18", 5000) expect(storage.getCookie("age2")).toBe("18"); }); test("getCookie:cookie取值", () => { //在VSCode测试OK,浏览器没有安装js-Cookies无法测试 storage.setCookie("name2", "嫦娥", 5000) expect(storage.getCookie("name2")).toBe("嫦娥"); }); test("removeCookie:删除cookie值", () => { //在VSCode测试OK,浏览器没有安装js-Cookies无法测试 storage.setCookie("class2", "幼儿园22班", 5000) expect(storage.removeCookie("class2")).toBe(undefined); }); test("clearCookie:清除所有cookie存值", () => { //在VSCode测试OK,浏览器没有安装js-Cookies无法测试 let target = "数据已清空"; expect(storage.clearCookie()).toBe(target); }); });