yeahoffline / redis-mock

Node.js redis client mock
212 stars 110 forks source link

RedisClient does not have connect() method implementation #211

Open ParagWankhade opened 1 year ago

ParagWankhade commented 1 year ago

The node-redis RedisClient module has a connect method that initates the connection. The same is missing in the mock class.

benpbolton commented 7 months ago

Eg. for a jest extension:

// Extend redis-mock to include isOpen, connect, and disconnect
jest.mock('redis', () => {
  const redisMock = jest.requireActual('redis-mock');
  const enhancedRedisMock = {
    ...redisMock,
    createClient: () => {
      const client = redisMock.createClient();
      client.isOpen = true;
      client.connect = jest.fn().mockResolvedValue(null);
      client.disconnect = jest.fn().mockResolvedValue(null);
      return client;
    },
  };
  return enhancedRedisMock;
});