MCPcopy Index your code
hub / github.com/coder/coder / localStorageMock

Function localStorageMock

site/src/testHelpers/localStorage.ts:1–32  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1const localStorageMock = (): Storage => {
2 const store = new Map<string, string>();
3
4 return {
5 getItem: (key) => {
6 return store.get(key) ?? null;
7 },
8 setItem: (key: string, value: string) => {
9 store.set(key, value);
10 },
11 clear: () => {
12 store.clear();
13 },
14 removeItem: (key: string) => {
15 store.delete(key);
16 },
17
18 get length() {
19 return store.size;
20 },
21
22 key: (index) => {
23 const values = store.values();
24 let value: IteratorResult<string, undefined> = values.next();
25 for (let i = 1; i < index && !value.done; i++) {
26 value = values.next();
27 }
28
29 return value.value ?? null;
30 },
31 };
32};
33
34Object.defineProperty(globalThis, "localStorage", {
35 value: localStorageMock(),

Callers 1

localStorage.tsFile · 0.85

Calls 4

getMethod · 0.80
clearMethod · 0.80
nextMethod · 0.80
setMethod · 0.45

Tested by

no test coverage detected