Skip to content

Instantly share code, notes, and snippets.

@lucasraziel
Created May 13, 2022 21:03
Show Gist options
  • Save lucasraziel/b0b6fb6cab40b803ad9cf97cbc6029a3 to your computer and use it in GitHub Desktop.
Save lucasraziel/b0b6fb6cab40b803ad9cf97cbc6029a3 to your computer and use it in GitHub Desktop.
test.js test for time
it('should be able to remove value after some time', async () => {
const data: Data<number> = {
key: 'test',
data: 1,
};
jest.useFakeTimers();
fakeCacheProvider.save(data, 'app:', { ttlInSeconds: 3 });
const dataRecovered = await fakeCacheProvider.recover<number>(
'test',
'app:'
);
expect(dataRecovered).toBe(1);
jest.runAllTimers();
const newDataRecovered = await fakeCacheProvider.recover<number>(
'test',
'app:'
);
expect(newDataRecovered).toBe(null);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment