Skip to content

Commit

Permalink
test: ensure pending values are not used after TTL
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiphe committed Jan 10, 2023
1 parent 9979a88 commit fa175f5
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/cachified.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,30 @@ describe('cachified', () => {
`);
});

it('does not use pending values after TTL is over', async () => {
const cache = new Map<string, CacheEntry>();
const reporter = createReporter();
const getValue = (
getFreshValue: CachifiedOptions<string>['getFreshValue'],
) =>
cachified({
cache,
ttl: 5,
key: 'test',
reporter,
getFreshValue,
});

const d = new Deferred<string>();
const pValue1 = getValue(() => d.promise);
currentTime = 6;
const pValue2 = getValue(() => 'TWO');

d.resolve('ONE');
expect(await pValue1).toBe('ONE');
expect(await pValue2).toBe('TWO');
});

it('resolves earlier pending values with faster responses from later calls', async () => {
const cache = new Map<string, CacheEntry>();
const getValue = (
Expand Down

0 comments on commit fa175f5

Please sign in to comment.