store.jest.ts 865 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import store from "../store";
  2. Object.assign(window, {
  3. localStorage: {
  4. removeItem(key) {
  5. delete window.localStorage[key];
  6. }
  7. }
  8. });
  9. describe("store", () => {
  10. it("should store", () => {
  11. store.set("key1", "123");
  12. expect(store.get("key1")).toBe("123");
  13. });
  14. it("get key when undefined", () => {
  15. expect(store.get("key2")).toBe(undefined);
  16. });
  17. it("check if key exixts", () => {
  18. store.set("key3", "123");
  19. expect(store.exists("key3")).toBe(true);
  20. });
  21. it("get boolean when no key", () => {
  22. expect(store.getBool("key4", false)).toBe(false);
  23. });
  24. it("get boolean", () => {
  25. store.set("key5", "true");
  26. expect(store.getBool("key5", false)).toBe(true);
  27. });
  28. it("key should be deleted", () => {
  29. store.set("key6", "123");
  30. store.delete("key6");
  31. expect(store.exists("key6")).toBe(false);
  32. });
  33. });