diff --git a/src/cache/local-storage-assignment-cache.spec.ts b/src/cache/local-storage-assignment-cache.spec.ts index be5c58bc..9803ce94 100644 --- a/src/cache/local-storage-assignment-cache.spec.ts +++ b/src/cache/local-storage-assignment-cache.spec.ts @@ -5,6 +5,15 @@ import { LocalStorageAssignmentCache } from './local-storage-assignment-cache'; describe('LocalStorageAssignmentCache', () => { + beforeEach(() => { + window.localStorage.clear(); + }); + + it('does not crash when localStorage contains a key named "undefined"', () => { + window.localStorage.setItem('undefined', 'not-json'); + expect(() => new LocalStorageAssignmentCache('test')).not.toThrow(); + }); + it('typical behavior', () => { const cache = new LocalStorageAssignmentCache('test'); expect( diff --git a/src/cache/local-storage-assignment-shim.ts b/src/cache/local-storage-assignment-shim.ts index 57327b06..59332ce4 100644 --- a/src/cache/local-storage-assignment-shim.ts +++ b/src/cache/local-storage-assignment-shim.ts @@ -28,7 +28,9 @@ export class LocalStorageAssignmentShim implements Map { this.getCache().forEach(callbackfn, thisArg); } - size: number = this.getCache().size; + get size(): number { + return this.getCache().size; + } entries(): IterableIterator<[string, string]> { return this.getCache().entries(); @@ -46,7 +48,7 @@ export class LocalStorageAssignmentShim implements Map { return this.getCache()[Symbol.iterator](); } - [Symbol.toStringTag]: string = this.getCache()[Symbol.toStringTag]; + [Symbol.toStringTag] = 'Map'; public has(key: string): boolean { return this.getCache().has(key);