Files
loldle/web/test/setup-local-storage.js
T
tiennm99 d0c75e84b1 test: add characterization tests for lib layer
Cover classic-mode comparison rules, game-engine state machine and
localStorage persistence, and champion-data search/seeding/loading with
Vitest. Storage keys are asserted literally so returning players' saved
games and stats cannot silently break.

Node environment with a hand-rolled localStorage stub; fixtures are four
hand-written champions so the weekly data sync cannot destabilise the
suite.
2026-07-25 10:54:36 +07:00

38 lines
641 B
JavaScript

import { beforeEach, vi } from "vitest";
/**
* Minimal spec-shaped localStorage stub.
* `key(i)` and `length` are required: clearExpiredCache iterates by index.
*/
class LocalStorageStub {
#store = new Map();
get length() {
return this.#store.size;
}
key(i) {
return [...this.#store.keys()][i] ?? null;
}
getItem(k) {
return this.#store.has(k) ? this.#store.get(k) : null;
}
setItem(k, v) {
this.#store.set(k, String(v));
}
removeItem(k) {
this.#store.delete(k);
}
clear() {
this.#store.clear();
}
}
beforeEach(() => {
vi.stubGlobal("localStorage", new LocalStorageStub());
});