ditto/src/utils/SimpleLRU.test.ts
2024-09-22 16:06:10 -05:00

21 lines
510 B
TypeScript

import { SimpleLRU } from '@/utils/SimpleLRU.ts';
import { assertEquals, assertRejects } from '@std/assert';
Deno.test("SimpleLRU doesn't repeat failed calls", async () => {
let calls = 0;
const cache = new SimpleLRU(
// deno-lint-ignore require-await
async () => {
calls++;
throw new Error('gg');
},
{ max: 100 },
);
await assertRejects(() => cache.fetch('foo'));
assertEquals(calls, 1);
await assertRejects(() => cache.fetch('foo'));
assertEquals(calls, 1);
});