Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

redisMock does not recognize keys set using setEx when testing with jest #193

Open
vamsiampolu opened this issue Jul 30, 2021 · 0 comments

Comments

@vamsiampolu
Copy link

I have a key foo that I set to bar to expire in 2 seconds. I'm testing this using redis-mock using jest fake timers. I always get -1 (no expiry associated with key).

Node Version: v14.17.0
redis Version: ^3.0.2
redis-mock Version: ^0.56.3

import { promisify } from 'util';
import * as redis from 'redis-mock';

jest.mock('redis' => redis)

const { redisClient, setEx } = require('./redis');

const ttl = promisify(redisClient.ttl).bind(redisClient);

describe('redisService', () => {
  it('returns the ttl for a key set using setEx', async () => {
       jest.useFakeTimers();
       await setEx('foo', 2, 'bar');
      const sec = await ttl('foo');
      expect(sec).toEqual(2); 
      jest.clearAllTimers();
     jest.useRealTimers();
  })
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant