yeahoffline / redis-mock

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

Added Support for using jest mock functions #207

Open seanlion opened 2 years ago

seanlion commented 2 years ago

Overview

A workaround for returning values to use jest mock functions. I think it would be helpful for users who wants to integrate with jest.

Usage

var redis_client = require("redis-mock")
jest.fn().mockImplementation(async (args) => {
    const result = await new Promise((resolve, reject) => {
        redis_client.command(args, function(err,result)
         {
            resolve(result);
         });
    });
    return result;
});