ditto/packages/utils/SimpleLRU.test.ts
2025-02-17 15:32:18 -06:00

21 lines
504 B
TypeScript

import { SimpleLRU } from './SimpleLRU.ts';
import { assertEquals, assertRejects } from '@std/assert';
Deno.test("SimpleLRU doesn't repeat failed calls", async () => {
let calls = 0;
using 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);
});