Skip to content

Commit

Permalink
Merge pull request #29 from thalesrc/bugfix/smart-map/null-error
Browse files Browse the repository at this point in the history
fix(SmartMap): fixed null value error
  • Loading branch information
alisahinozcelik authored Apr 1, 2020
2 parents 851b799 + b83f629 commit d5dee59
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/smart-map.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/smart-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,6 @@ export class SmartMap<K = any, V = any> extends Map<K, V> {
* @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);
}
}

0 comments on commit d5dee59

Please sign in to comment.