Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/cache/local-storage-assignment-cache.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
8 changes: 6 additions & 2 deletions src/cache/local-storage-assignment-shim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ export class LocalStorageAssignmentShim implements Map<string, string> {
this.getCache().forEach(callbackfn, thisArg);
}

size: number = this.getCache().size;
get size(): number {
return this.getCache().size;
}
Comment thread
bertilhatt marked this conversation as resolved.

entries(): IterableIterator<[string, string]> {
return this.getCache().entries();
Expand All @@ -46,7 +48,9 @@ export class LocalStorageAssignmentShim implements Map<string, string> {
return this.getCache()[Symbol.iterator]();
}

[Symbol.toStringTag]: string = this.getCache()[Symbol.toStringTag];
get [Symbol.toStringTag](): string {
return 'Map';
}
Comment thread
bertilhatt marked this conversation as resolved.
Outdated

public has(key: string): boolean {
return this.getCache().has(key);
Expand Down
Loading