diff --git a/src/smart-map.spec.ts b/src/smart-map.spec.ts index 4bf0c50..b0b9653 100644 --- a/src/smart-map.spec.ts +++ b/src/smart-map.spec.ts @@ -23,8 +23,9 @@ describe('SmartMap Class', () => { map.set(true, 'boolean'); map.set(Symbol(), 'symbol'); map.set(undefined, 'undefined'); + map.set(null, 'null'); - expect(map.size).toBe(5); + expect(map.size).toBe(6); }); it('should set a value by object type keys', () => { @@ -58,9 +59,11 @@ describe('SmartMap Class', () => { map.set(1, '1'); map.set(anObj, 'an object'); + map.set(null, 'null'); expect(map.get(1)).toBe('1'); expect(map.get(anObj)).toBe('an object'); + expect(map.get(null)).toBe('null'); }); it('should delete value when delete method called via both primitive and object key', () => { diff --git a/src/smart-map.ts b/src/smart-map.ts index 62d5281..07e275d 100644 --- a/src/smart-map.ts +++ b/src/smart-map.ts @@ -108,6 +108,6 @@ export class SmartMap extends Map { * @returns A boolean whether if the key is storable in weakmap or not */ protected isStorableInWeakMap(key: K): boolean { - return SmartMap.TYPES_TO_STORE_IN_WEAKMAP.some(_key => typeof key === _key); + return key !== null && SmartMap.TYPES_TO_STORE_IN_WEAKMAP.some(_key => typeof key === _key); } }