Click here to Skip to main content
15,561,009 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have one method which is removing the data from redis and I have to write a unit test for that but when I am mocking the internal method it is always returning zero

What I have tried:


const configValues = require('../../config/config');
const constants = require('../../helper/constants');
const asyncRedis = require('async-redis');
const redisClient  = asyncRedis.createClient({
  port: configValues.redisPort,
  host: configValues.redisHost
module.exports = {
    clearDataFromRedis: async(userId) => {
      let removeUserDetails=await redisClient.del(userId+'_userDetails');
      return removeUserDetails;
closeRedisInstance :()=>{


const {clearDataFromRedis ,closeRedisInstance} = require('../..//../src/shared-module/service');
const redis_mock = require("redis-mock");
const client = redis_mock.createClient();

  it('should clear data from redis',async ()=>{
        const result=await clearDataFromRedis('userData');
afterAll(() => closeRedisInstance());

after running test it is always returning zero instead of 1

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900