Skip to content

Commit

Permalink
test added for non-existent key
Browse files Browse the repository at this point in the history
  • Loading branch information
cnoelle committed Sep 23, 2024
1 parent 00179a6 commit fdfe16e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
1 change: 0 additions & 1 deletion src/impl/Table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,6 @@ export class Table<T> /*implements LruCacheIndexedDB<T>*/ {
return this.get(key, options).then(r => r !== undefined);
}

// TODO what happens if no such item exists?
async #getInternal(key: string, options?: CacheRequestOptions): Promise<T|undefined> {
const store = this.#objectStore;
const db = await this.#dbLoader(options);
Expand Down
7 changes: 7 additions & 0 deletions test/testCacheWithMemory.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ test("Empty memory cache works", async t => {
await defaultCache.close();
});

test("Retrieving a non-existent value works with memory cache", async t => {
const defaultCache = createFakeIdb({memoryConfig: { maxItemsInMemory: 5 }});
const result = await defaultCache.get("test");
t.is(result, undefined);
await defaultCache.close();
});

test("set() works for memory cache", async t => {
const defaultCache = createFakeIdb({memoryConfig: { maxItemsInMemory: 5 }});
const obj1 = {a: "test1", b: 1};
Expand Down
7 changes: 7 additions & 0 deletions test/testDefaultCache.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ test("Empty default cache works", async t => {
await defaultCache.close();
});

test("Retrieving a non-existent value works with the default cache", async t => {
const defaultCache = createFakeIdb();
const result = await defaultCache.get("test");
t.is(result, undefined);
await defaultCache.close();
});

test("set() works for default cache", async t => {
const defaultCache = createFakeIdb();
const obj1 = {a: "test1", b: 1};
Expand Down

0 comments on commit fdfe16e

Please sign in to comment.