Skip to content

Commit

Permalink
test: updated store expiration test with fake timers
Browse files Browse the repository at this point in the history
  • Loading branch information
schaechinger committed Aug 17, 2021
1 parent c909e3b commit d0e3536
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions test/services/DataStore.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import findCacheDir from 'find-cache-dir';
import { accessSync, unlinkSync } from 'fs';
import { join as joinPath } from 'path';
import { sync as rmdirSync } from 'rimraf';
import { stub } from 'sinon';
import { stub, useFakeTimers } from 'sinon';
import { DataStore } from '../../src/services/DataStore';
import { getLoggerStub } from '../stubs/logger.stub';

Expand Down Expand Up @@ -62,16 +62,16 @@ describe('DataStore', () => {
});

it('should reload the data after they are expired', async () => {
await store.init(tmpFile, loadData, 0.01);
const clock = useFakeTimers();

await new Promise<void>(resolve => {
setTimeout(async () => {
await store.getList();
await store.init(tmpFile, loadData, 1);

expect(loadData.calledTwice).to.be.true;
resolve();
}, 11);
});
clock.tick(2000);

await store.getList();
expect(loadData.calledTwice).to.be.true;

clock.restore();
});

it('should reload the data with disabled cache', async () => {
Expand Down

0 comments on commit d0e3536

Please sign in to comment.