Skip to content

Commit

Permalink
Fix internal usage of toStringTag (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmomtchev committed Mar 26, 2022
1 parent b93929f commit 95593b6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ export default class QuickLRU extends Map {
}
}

[Symbol.toStringTag]() {
get [Symbol.toStringTag]() {
return JSON.stringify([...this.entriesAscending()]);
}
}
9 changes: 8 additions & 1 deletion test.js
Original file line number Diff line number Diff line change
Expand Up @@ -745,5 +745,12 @@ test('[Symbol.toStringTag] converts the cache items to a string in ascending ord
const lru = new QuickLRU({maxSize: 2});
lru.set('1', 1);
lru.set('2', 2);
t.is(lru[Symbol.toStringTag](), '[["1",1],["2",2]]');
t.is(lru[Symbol.toStringTag], '[["1",1],["2",2]]');
});

test('toString() works as expected', t => {
const lru = new QuickLRU({maxSize: 2});
lru.set('1', 1);
lru.set('2', 2);
t.is(lru.toString(), '[object [["1",1],["2",2]]]');
});

0 comments on commit 95593b6

Please sign in to comment.