separate get into get and getMaybe
This commit is contained in:
parent
a1265f4c45
commit
a2ddeb28c3
3 changed files with 43 additions and 12 deletions
|
|
@ -220,10 +220,29 @@ describe(QuantumKVCache, () => {
|
|||
expect(result).toBe('bar');
|
||||
});
|
||||
|
||||
it('should throw KeyNotFoundError if missing', () => {
|
||||
const cache = makeCache<string>();
|
||||
|
||||
assert.throws(KeyNotFoundError, () => {
|
||||
cache.get('foo');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('getMaybe', () => {
|
||||
it('should return value if present', async () => {
|
||||
const cache = makeCache<string>();
|
||||
await cache.set('foo', 'bar');
|
||||
|
||||
const result = cache.getMaybe('foo');
|
||||
|
||||
expect(result).toBe('bar');
|
||||
});
|
||||
|
||||
it('should return undefined if missing', () => {
|
||||
const cache = makeCache<string>();
|
||||
|
||||
const result = cache.get('foo');
|
||||
const result = cache.getMaybe('foo');
|
||||
|
||||
expect(result).toBe(undefined);
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue